Skip to content

Commit ef7810c

Browse files
Fix #10995. Default to local time for mythshutdown --setwakeup.
1 parent 35ff26d commit ef7810c

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

mythtv/programs/mythshutdown/commandlineparser.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ void MythShutdownCommandLineParser::LoadArguments(void)
2222
CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
2323
<< add(QStringList( QStringList() << "-w" << "--setwakeup" ),
2424
"setwakeup", "",
25-
"Set the wakeup time (yyyy-MM-ddThh:mm:ss)", "")
25+
"Set the wakeup time (yyyy-MM-ddThh:mm:ss) "
26+
"default is in local time", "")
2627
<< add(QStringList( QStringList() << "-t" << "--setscheduledwakeup" ),
2728
"setschedwakeup", false,
2829
"Set wakeup time to the next scheduled recording", "")
@@ -66,5 +67,16 @@ void MythShutdownCommandLineParser::LoadArguments(void)
6667
" 64 - In daily wakeup/shutdown period\n"
6768
" 128 - Less than 15 minutes to next wakeup period\n"
6869
" 255 - Setup is running") );
70+
71+
// The localtime command line parameter exists solely to make scripts
72+
// using this executable self documenting.
73+
74+
CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
75+
<< add("--utc",
76+
"utc", false,
77+
"Specify that the wakeup time is in utc", "")
78+
<< add("--localtime",
79+
"localtime", false,
80+
"Specify that the wakeup time is in local time", "") );
6981
}
7082

mythtv/programs/mythshutdown/main.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -377,31 +377,16 @@ static int checkOKShutdown(bool bWantRecStatus)
377377
return res;
378378
}
379379

380-
static int setWakeupTime(QString sWakeupTime)
380+
static void setWakeupTime(const QDateTime &wakeupTime)
381381
{
382382
LOG(VB_GENERAL, LOG_INFO, "Mythshutdown: --setwakeup");
383383

384384
LOG(VB_GENERAL, LOG_NOTICE,
385-
QString("Mythshutdown: wakeup time given is: %1").arg(sWakeupTime));
386-
387-
// check time given is valid
388-
QDateTime dtWakeupTime;
389-
dtWakeupTime = MythDate::fromString(sWakeupTime);
390-
391-
if (!dtWakeupTime.isValid())
392-
{
393-
LOG(VB_GENERAL, LOG_ERR,
394-
QString("Mythshutdown: --setwakeup invalid date "
395-
"format (%1)\n\t\t\t"
396-
"must be yyyy-MM-ddThh:mm:ss")
397-
.arg(sWakeupTime));
398-
return 1;
399-
}
385+
QString("Mythshutdown: wakeup time given is: %1 (local time)")
386+
.arg(MythDate::toString(wakeupTime)));
400387

401388
setGlobalSetting("MythShutdownNextScheduled",
402-
MythDate::toString(dtWakeupTime, MythDate::kDatabase));
403-
404-
return 0;
389+
MythDate::toString(wakeupTime, MythDate::kDatabase));
405390
}
406391

407392
static int setScheduledWakeupTime()
@@ -434,7 +419,7 @@ static int setScheduledWakeupTime()
434419
if (add)
435420
restarttime = restarttime.addSecs((-1) * add);
436421

437-
setWakeupTime(restarttime.toString(Qt::ISODate));
422+
setWakeupTime(restarttime);
438423

439424
return 0;
440425
}
@@ -823,7 +808,30 @@ int main(int argc, char **argv)
823808
else if (cmdline.toBool("status"))
824809
res = getStatus((bool)(cmdline.toInt("status") == 1));
825810
else if (cmdline.toBool("setwakeup"))
826-
res = setWakeupTime(cmdline.toString("setwakeup"));
811+
{
812+
// only one of --utc or --localtime can be passed per
813+
// CommandLineArg::AllowOneOf() in commandlineparser.cpp
814+
bool utc = cmdline.toBool("utc");
815+
QString tmp = cmdline.toString("setwakeup");
816+
817+
QDateTime wakeuptime = (utc) ?
818+
MythDate::fromString(tmp) :
819+
QDateTime::fromString(tmp, Qt::ISODate).toUTC();
820+
821+
if (!wakeuptime.isValid())
822+
{
823+
cerr << qPrintable(
824+
QObject::tr("mythshutdown: --setwakeup invalid date "
825+
"format (%1)\n\t\t\t"
826+
"must be yyyy-MM-ddThh:mm:ss")
827+
.arg(tmp)) << endl;
828+
res = 1;
829+
}
830+
else
831+
{
832+
setWakeupTime(wakeuptime);
833+
}
834+
}
827835
else if (cmdline.toBool("safeshutdown"))
828836
{
829837
res = checkOKShutdown(true);

0 commit comments

Comments
 (0)