diff --git a/src/Components/DateTime/DateTimeController.cpp b/src/Components/DateTime/DateTimeController.cpp index ed6d70fb..5cfa08eb 100644 --- a/src/Components/DateTime/DateTimeController.cpp +++ b/src/Components/DateTime/DateTimeController.cpp @@ -7,25 +7,23 @@ using namespace Pinetime::Controllers; void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) { + std::tm tm = { /* .tm_sec = */ second, + /* .tm_min = */ minute, + /* .tm_hour = */ hour, + /* .tm_mday = */ day, + /* .tm_mon = */ month - 1, + /* .tm_year = */ year - 1900, + }; + tm.tm_isdst = -1; // Use DST value from local time zone + currentDateTime = std::chrono::system_clock::from_time_t(std::mktime(&tm)); - currentDateTime = {}; - currentDateTime += date::years( year-1970); - currentDateTime += date::days( day - 1); - currentDateTime += date::months( month - 1); - - currentDateTime += std::chrono::hours(hour); - currentDateTime += std::chrono::minutes (minute); - currentDateTime += std::chrono::seconds (second); - - currentDateTime -= std::chrono::hours(3); // TODO WHYYYY? NRF_LOG_INFO("%d %d %d ", day, month, year); NRF_LOG_INFO("%d %d %d ", hour, minute, second); previousSystickCounter = systickCounter; + UpdateTime(systickCounter); NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second); NRF_LOG_INFO("* %d %d %d ", this->day, this->month, this->year); - - } void DateTime::UpdateTime(uint32_t systickCounter) { diff --git a/src/Components/DateTime/DateTimeController.h b/src/Components/DateTime/DateTimeController.h index 9e7392cd..1e65bd11 100644 --- a/src/Components/DateTime/DateTimeController.h +++ b/src/Components/DateTime/DateTimeController.h @@ -20,7 +20,7 @@ namespace Pinetime { uint8_t Minutes() const { return minute; } uint8_t Seconds() const { return second; } - std::chrono::time_point CurrentDateTime() const { return currentDateTime; } + std::chrono::time_point CurrentDateTime() const { return currentDateTime; } private: uint16_t year = 0; Months month = Months::Unknown; @@ -31,7 +31,7 @@ namespace Pinetime { uint8_t second = 0; uint32_t previousSystickCounter = 0; - std::chrono::time_point currentDateTime; + std::chrono::time_point currentDateTime; }; } diff --git a/src/DisplayApp/Screens/Clock.h b/src/DisplayApp/Screens/Clock.h index d6e44fda..d14595b0 100644 --- a/src/DisplayApp/Screens/Clock.h +++ b/src/DisplayApp/Screens/Clock.h @@ -63,7 +63,7 @@ namespace Pinetime { DirtyValue batteryPercentRemaining {0}; DirtyValue bleState {false}; - DirtyValue> currentDateTime; + DirtyValue> currentDateTime; DirtyValue version; lv_style_t* labelStyle;