diff --git a/src/gui/sleeptimer.cpp b/src/gui/sleeptimer.cpp index b34caddde..8779552cd 100644 --- a/src/gui/sleeptimer.cpp +++ b/src/gui/sleeptimer.cpp @@ -108,12 +108,15 @@ int CSleepTimerWidget::exec(CMenuTarget* parent, const std::string &actionKey) printf("sleeptimer min: %d\n", shutdown_min); if (shutdown_min == 0) // if set to zero remove existing sleeptimer { - if(g_Timerd->getSleeptimerID() > 0) { - g_Timerd->removeTimerEvent(g_Timerd->getSleeptimerID()); - } + int timer_id = g_Timerd->getSleeptimerID(); + if (timer_id > 0) + g_Timerd->removeTimerEvent(timer_id); } else // set the sleeptimer to actual time + shutdown mins and announce 1 min before - g_Timerd->setSleeptimer(time(NULL) + ((shutdown_min -1) * 60),time(NULL) + shutdown_min * 60,0); + { + time_t now = time(NULL); + g_Timerd->setSleeptimer(now + (shutdown_min - 1) * 60, now + shutdown_min * 60, 0); + } } is_running = false;