summaryrefslogtreecommitdiff
path: root/src/components/datetime/DateTimeController.cpp
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-04-20 17:45:20 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-04-20 17:45:20 (GMT)
commit822ec38fde294dfc2a19fd83fe463fc0d7b3ee2d (patch)
tree43e006a2890832c3778a4dbcc0920483ce63ed17 /src/components/datetime/DateTimeController.cpp
parentbe01602fcb6dc9cd91df702658c0b52da74023a9 (diff)
parentaca605d4fb4040cc80c1acf101023aa86e7694ba (diff)
Merge branch 'alarm-reliability-and-switch-to-freertos-timers' into rev22-develop
Diffstat (limited to 'src/components/datetime/DateTimeController.cpp')
-rw-r--r--src/components/datetime/DateTimeController.cpp33
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);
}