|
7 | 7 | using namespace Pinetime::Controllers;
|
8 | 8 |
|
9 | 9 | namespace {
|
10 |
| - char const* DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; |
11 |
| - char const* DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; |
12 |
| - char const* MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; |
13 |
| - char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
| 10 | + constexpr const char* const DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; |
| 11 | + constexpr const char* const DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; |
| 12 | + constexpr const char* const MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; |
| 13 | + constexpr const char* const MonthsStringLow[] = |
| 14 | + {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
| 15 | + |
| 16 | + constexpr int compileTimeAtoi(const char* str) { |
| 17 | + int result = 0; |
| 18 | + while (*str >= '0' && *str <= '9') { |
| 19 | + result = result * 10 + *str - '0'; |
| 20 | + str++; |
| 21 | + } |
| 22 | + return result; |
| 23 | + } |
14 | 24 | }
|
15 | 25 |
|
16 | 26 | DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} {
|
17 | 27 | mutex = xSemaphoreCreateMutex();
|
18 | 28 | ASSERT(mutex != nullptr);
|
19 | 29 | xSemaphoreGive(mutex);
|
| 30 | + |
| 31 | + // __DATE__ is a string of the format "MMM DD YYYY", so an offset of 7 gives the start of the year |
| 32 | + SetTime(compileTimeAtoi(&__DATE__[7]), 1, 1, 0, 0, 0); |
20 | 33 | }
|
21 | 34 |
|
22 | 35 | 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,
|
46 | 59 | UpdateTime(previousSystickCounter, true);
|
47 | 60 | xSemaphoreGive(mutex);
|
48 | 61 |
|
49 |
| - systemTask->PushMessage(System::Messages::OnNewTime); |
| 62 | + if (systemTask != nullptr) { |
| 63 | + systemTask->PushMessage(System::Messages::OnNewTime); |
| 64 | + } |
50 | 65 | }
|
51 | 66 |
|
52 | 67 | void DateTime::SetTimeZone(int8_t timezone, int8_t dst) {
|
|
0 commit comments