diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 2ef0ef22f1..63038636d3 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -14,24 +14,12 @@ namespace { constexpr const char* const MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; constexpr const char* const MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - - constexpr int compileTimeAtoi(const char* str) { - int result = 0; - while (*str >= '0' && *str <= '9') { - result = result * 10 + *str - '0'; - str++; - } - return result; - } } DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} { mutex = xSemaphoreCreateMutex(); ASSERT(mutex != nullptr); xSemaphoreGive(mutex); - - // __DATE__ is a string of the format "MMM DD YYYY", so an offset of 7 gives the start of the year - SetTime(compileTimeAtoi(&__DATE__[7]), 1, 1, 0, 0, 0); } void DateTime::SetCurrentTime(std::chrono::time_point t) { diff --git a/src/main.cpp b/src/main.cpp index d0ab3e4887..b178934a41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ #include "systemtask/SystemTask.h" #include "touchhandler/TouchHandler.h" #include "buttonhandler/ButtonHandler.h" +#include "utility/Math.h" #if NRF_LOG_ENABLED #include "logging/NrfLogger.h" @@ -355,6 +356,9 @@ int main() { if (NoInit_MagicWord == NoInit_MagicValue) { dateTimeController.SetCurrentTime(NoInit_BackUpTime); } else { + // __DATE__ is a string of the format "MMM DD YYYY", so an offset of 7 gives the start of the year + dateTimeController.SetTime(Pinetime::Utility::CompileTimeAtoi(&__DATE__[7]), 1, 1, 0, 0, 0); + // Clear Memory to known state memset(&__start_noinit_data, 0, (uintptr_t) &__stop_noinit_data - (uintptr_t) &__start_noinit_data); NoInit_MagicWord = NoInit_MagicValue; diff --git a/src/utility/Math.h b/src/utility/Math.h index 314e4e373e..3c65303c32 100644 --- a/src/utility/Math.h +++ b/src/utility/Math.h @@ -29,5 +29,14 @@ namespace Pinetime { } return res; } + + constexpr int CompileTimeAtoi(const char* str) { + int result = 0; + while (*str >= '0' && *str <= '9') { + result = result * 10 + *str - '0'; + str++; + } + return result; + } } }