aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/datetime/DateTimeController.cpp
diff options
context:
space:
mode:
authorFintasticMan <finlay.neon.kid@gmail.com>2024-10-03 00:08:46 +0200
committerJF <JF002@users.noreply.github.com>2024-10-27 17:01:07 +0100
commitf1651c8000f355a87ca601a20d87d1c0aefc545e (patch)
tree1389b5ffabb3ac7fe8edbb8e220cb32520fa34ca /src/components/datetime/DateTimeController.cpp
parent8a2ee437f52312cbe22741023cbbe9cec7b4e8f6 (diff)
datetime: Set the default year to the year during compile
Diffstat (limited to 'src/components/datetime/DateTimeController.cpp')
-rw-r--r--src/components/datetime/DateTimeController.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index 7f58c9b3..d439821b 100644
--- a/src/components/datetime/DateTimeController.cpp
+++ b/src/components/datetime/DateTimeController.cpp
@@ -7,16 +7,29 @@
using namespace Pinetime::Controllers;
namespace {
- char const* DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
- char const* DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
- char const* MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
- char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+ constexpr const char* const DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
+ constexpr const char* const DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+ 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<std::chrono::system_clock, std::chrono::nanoseconds> t) {
@@ -46,7 +59,9 @@ void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour,
UpdateTime(previousSystickCounter, true);
xSemaphoreGive(mutex);
- systemTask->PushMessage(System::Messages::OnNewTime);
+ if (systemTask != nullptr) {
+ systemTask->PushMessage(System::Messages::OnNewTime);
+ }
}
void DateTime::SetTimeZone(int8_t timezone, int8_t dst) {