diff options
Diffstat (limited to 'src/components/datetime')
| -rw-r--r-- | src/components/datetime/DateTimeController.cpp | 16 | ||||
| -rw-r--r-- | src/components/datetime/DateTimeController.h | 72 |
2 files changed, 72 insertions, 16 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 4dc16329..b744fbb2 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -20,14 +20,7 @@ void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, UpdateTime(previousSystickCounter); // Update internal state without updating the time } -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) { +void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) { std::tm tm = { /* .tm_sec = */ second, /* .tm_min = */ minute, @@ -36,6 +29,7 @@ void DateTime::SetTime(uint16_t year, /* .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)); @@ -50,6 +44,11 @@ void DateTime::SetTime(uint16_t year, systemTask->PushMessage(System::Messages::OnNewTime); } +void DateTime::SetTimeZone(int8_t timezone, int8_t dst) { + tzOffset = timezone; + dstOffset = dst; +} + void DateTime::UpdateTime(uint32_t systickCounter) { // Handle systick counter overflow uint32_t systickDelta = 0; @@ -136,6 +135,7 @@ void DateTime::Register(Pinetime::System::SystemTask* systemTask) { } using ClockType = Pinetime::Controllers::Settings::ClockType; + std::string DateTime::FormattedTime() { // Return time as a string in 12- or 24-hour format char buff[9]; diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index 81319d15..74ccf4da 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -9,6 +9,7 @@ namespace Pinetime { namespace System { class SystemTask; } + namespace Controllers { class DateTime { public: @@ -30,37 +31,85 @@ namespace Pinetime { December }; - void 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); + void SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter); + + /* + * setter corresponding to the BLE Set Local Time characteristic. + * + * used to update difference between utc and local time (see UtcOffset()) + * + * parameters are in quarters of an our. Following the BLE CTS specification, + * timezone is expected to be constant over DST which will be reported in + * dst field. + */ + void SetTimeZone(int8_t timezone, int8_t dst); + void UpdateTime(uint32_t systickCounter); + uint16_t Year() const { return year; } + Months Month() const { return month; } + uint8_t Day() const { return day; } + Days DayOfWeek() const { return dayOfWeek; } + uint8_t Hours() const { return hour; } + uint8_t Minutes() const { return minute; } + uint8_t Seconds() const { return second; } + /* + * returns the offset between local time and UTC in quarters of an hour + * + * Availability of this field depends on wether the companion app + * supports the BLE CTS Local Time Characteristic. Expect it to be 0 + * if not. + */ + int8_t UtcOffset() const { + return tzOffset + dstOffset; + } + + /* + * returns the offset between the (dst independent) local time zone and UTC + * in quarters of an hour + * + * Availability of this field depends on wether the companion app + * supports the BLE CTS Local Time Characteristic. Expect it to be 0 + * if not. + */ + int8_t TzOffset() const { + return tzOffset; + } + + /* + * returns the offset between the local time zone and local time + * in quarters of an hour + * if != 0, DST is in effect, if == 0 not. + * + * Availability of this field depends on wether the companion app + * supports the BLE CTS Local Time Characteristic. Expect it to be 0 + * if not. + */ + int8_t DstOffset() const { + return dstOffset; + } + const char* MonthShortToString() const; const char* DayOfWeekShortToString() const; static const char* MonthShortToStringLow(Months month); @@ -69,6 +118,11 @@ namespace Pinetime { std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; } + + std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> UTCDateTime() const { + return currentDateTime - std::chrono::seconds((tzOffset + dstOffset) * 15 * 60); + } + std::chrono::seconds Uptime() const { return uptime; } @@ -85,6 +139,8 @@ namespace Pinetime { uint8_t hour = 0; uint8_t minute = 0; uint8_t second = 0; + int8_t tzOffset = 0; + int8_t dstOffset = 0; uint32_t previousSystickCounter = 0; std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime; |
