diff --git a/src/ClockTool.cc b/src/ClockTool.cc index 514d45de..f11a7935 100644 --- a/src/ClockTool.cc +++ b/src/ClockTool.cc @@ -52,10 +52,19 @@ const char SWITCHES_12_24H[] = "lIrkHT"; const char SWITCHES_24_12H[] = "kHTlIr"; const char SWITCH_AM_PM[] = "pP"; -uint64_t calcNextTimeout() { +int showSeconds(const std::string& fmt) { + + return FbTk::StringUtil::findCharFromAlphabetAfterTrigger( + fmt, '%', SWITCHES_SECONDS, sizeof(SWITCHES_SECONDS), 0) != std::string::npos; +} + +uint64_t calcNextTimeout(const std::string& fmt) { uint64_t now = FbTk::FbTime::system(); uint64_t unit = FbTk::FbTime::IN_SECONDS; + if (!showSeconds(fmt)) { // microseconds till next full minute + unit *= 60L; + } return FbTk::FbTime::remainingNext(now, unit); } @@ -289,8 +298,7 @@ void ClockTool::updateTime() { } restart_timer: - m_timer.setTimeout(calcNextTimeout()); - m_timer.start(); + m_timer.setTimeout(calcNextTimeout(*m_timeformat), true); } // Just change things that affect the size diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc index 18065571..61875f7f 100644 --- a/src/FbTk/Timer.cc +++ b/src/FbTk/Timer.cc @@ -91,7 +91,7 @@ Timer::~Timer() { } -void Timer::setTimeout(uint64_t timeout) { +void Timer::setTimeout(uint64_t timeout, bool force_start) { bool was_timing = isTiming(); if (was_timing) { @@ -99,7 +99,7 @@ void Timer::setTimeout(uint64_t timeout) { } m_timeout = timeout; - if (was_timing) { + if (force_start || was_timing) { start(); } } diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh index 4bdd13ab..8904a853 100644 --- a/src/FbTk/Timer.hh +++ b/src/FbTk/Timer.hh @@ -43,7 +43,7 @@ public: ~Timer(); void fireOnce(bool once) { m_once = once; } - void setTimeout(uint64_t timeout); + void setTimeout(uint64_t timeout, bool force_start = false); void setCommand(const RefCount > &cmd); template