diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-05-12 00:19:59 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-05-12 00:19:59 (GMT) |
| commit | 72d0f103a8bc1048ff9729aee65070475977b5a3 (patch) | |
| tree | 6a806507701dcbea7eb30fa0351de9f3e59d7f56 /src/components/datetime/DateTimeController.cpp | |
| parent | 1ff0a48bbb66f8099c1451fa02983655003def8e (diff) | |
| parent | aca605d4fb4040cc80c1acf101023aa86e7694ba (diff) | |
Merge branch 'alarm-reliability-and-switch-to-freertos-timers' into analog24
Diffstat (limited to 'src/components/datetime/DateTimeController.cpp')
| -rw-r--r-- | src/components/datetime/DateTimeController.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 3bfbdc7..2656764 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -30,6 +30,7 @@ void DateTime::SetTime( /* .tm_year = */ year - 1900, }; tm.tm_isdst = -1; // Use DST value from local time zone + auto previousDateTime = currentDateTime; currentDateTime = std::chrono::system_clock::from_time_t(std::mktime(&tm)); NRF_LOG_INFO("%d %d %d ", day, month, year); @@ -40,7 +41,17 @@ void DateTime::SetTime( NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second); NRF_LOG_INFO("* %d %d %d ", this->day, this->month, this->year); - systemTask->PushMessage(System::Messages::OnNewTime); + decltype(currentDateTime - previousDateTime) timeDifference; + + if (currentDateTime > previousDateTime) { + timeDifference = currentDateTime - previousDateTime; + } else { + timeDifference = previousDateTime - currentDateTime; + } + + using namespace std::chrono_literals; + + systemTask->PushMessage(timeDifference < 3h ? System::Messages::OnAdjustTime : System::Messages::OnNewTime); } void DateTime::UpdateTime(uint32_t systickCounter) { @@ -129,16 +140,16 @@ std::string DateTime::FormattedTime() { // Return time as a string in 12- or 24-hour format char buff[9]; if (settingsController.GetClockType() == ClockType::H12) { - uint8_t hour12; - const char* amPmStr; - if (hour < 12) { - hour12 = (hour == 0) ? 12 : hour; - amPmStr = "AM"; - } else { - hour12 = (hour == 12) ? 12 : hour - 12; - amPmStr = "PM"; - } - sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr); + uint8_t hour12; + const char* amPmStr; + if (hour < 12) { + hour12 = (hour == 0) ? 12 : hour; + amPmStr = "AM"; + } else { + hour12 = (hour == 12) ? 12 : hour - 12; + amPmStr = "PM"; + } + sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr); } else { sprintf(buff, "%02i:%02i", hour, minute); } |
