11#include " components/datetime/DateTimeController.h"
2- #include < date/date.h>
32#include < libraries/log/nrf_log.h>
43#include < systemtask/SystemTask.h>
54
@@ -37,8 +36,6 @@ void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour,
3736 NRF_LOG_INFO (" %d %d %d " , hour, minute, second);
3837
3938 UpdateTime (previousSystickCounter);
40- NRF_LOG_INFO (" * %d %d %d " , this ->hour , this ->minute , this ->second );
41- NRF_LOG_INFO (" * %d %d %d " , this ->day , this ->month , this ->year );
4239
4340 systemTask->PushMessage (System::Messages::OnNewTime);
4441}
@@ -72,18 +69,11 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
7269 currentDateTime += std::chrono::seconds (correctedDelta);
7370 uptime += std::chrono::seconds (correctedDelta);
7471
75- auto dp = date::floor<date::days>(currentDateTime);
76- auto time = date::make_time (currentDateTime - dp);
77- auto yearMonthDay = date::year_month_day (dp);
72+ std::time_t currentTime = std::chrono::system_clock::to_time_t (currentDateTime);
73+ localTime = *std::localtime (¤tTime);
7874
79- year = static_cast <int >(yearMonthDay.year ());
80- month = static_cast <Months>(static_cast <unsigned >(yearMonthDay.month ()));
81- day = static_cast <unsigned >(yearMonthDay.day ());
82- dayOfWeek = static_cast <Days>(date::weekday (yearMonthDay).iso_encoding ());
83-
84- hour = time.hours ().count ();
85- minute = time.minutes ().count ();
86- second = time.seconds ().count ();
75+ auto minute = Minutes ();
76+ auto hour = Hours ();
8777
8878 if (minute == 0 && !isHourAlreadyNotified) {
8979 isHourAlreadyNotified = true ;
@@ -114,19 +104,19 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
114104}
115105
116106const char * DateTime::MonthShortToString () const {
117- return MonthsString[static_cast <uint8_t >(month )];
107+ return MonthsString[static_cast <uint8_t >(Month () )];
118108}
119109
120110const char * DateTime::DayOfWeekShortToString () const {
121- return DaysStringShort[static_cast <uint8_t >(dayOfWeek )];
111+ return DaysStringShort[static_cast <uint8_t >(DayOfWeek () )];
122112}
123113
124114const char * DateTime::MonthShortToStringLow (Months month) {
125115 return MonthsStringLow[static_cast <uint8_t >(month)];
126116}
127117
128118const char * DateTime::DayOfWeekShortToStringLow () const {
129- return DaysStringShortLow[static_cast <uint8_t >(dayOfWeek )];
119+ return DaysStringShortLow[static_cast <uint8_t >(DayOfWeek () )];
130120}
131121
132122void DateTime::Register (Pinetime::System::SystemTask* systemTask) {
@@ -136,6 +126,8 @@ void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
136126using ClockType = Pinetime::Controllers::Settings::ClockType;
137127
138128std::string DateTime::FormattedTime () {
129+ auto hour = Hours ();
130+ auto minute = Minutes ();
139131 // Return time as a string in 12- or 24-hour format
140132 char buff[9 ];
141133 if (settingsController.GetClockType () == ClockType::H12) {
0 commit comments