From 959778d770aedb56d773e7fde07c8c967d5b35eb Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 23 Feb 2023 19:15:23 +0200 Subject: DateTimeController: Use std::tm for storing date --- src/components/datetime/DateTimeController.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/components/datetime/DateTimeController.h') diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index b68d18ef..8e3fa8ff 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -2,6 +2,7 @@ #include #include +#include #include #include "components/settings/Settings.h" @@ -47,31 +48,35 @@ namespace Pinetime { void UpdateTime(uint32_t systickCounter); uint16_t Year() const { - return year; + return 1900 + localTime.tm_year; } Months Month() const { - return month; + return static_cast(localTime.tm_mon + 1); } uint8_t Day() const { - return day; + return localTime.tm_mday; } Days DayOfWeek() const { - return dayOfWeek; + int daysSinceSunday = localTime.tm_wday; + if (daysSinceSunday == 0) { + return Days::Sunday; + } + return static_cast(daysSinceSunday); } uint8_t Hours() const { - return hour; + return localTime.tm_hour; } uint8_t Minutes() const { - return minute; + return localTime.tm_min; } uint8_t Seconds() const { - return second; + return localTime.tm_sec; } /* @@ -132,13 +137,7 @@ namespace Pinetime { std::string FormattedTime(); private: - uint16_t year = 0; - Months month = Months::Unknown; - uint8_t day = 0; - Days dayOfWeek = Days::Unknown; - uint8_t hour = 0; - uint8_t minute = 0; - uint8_t second = 0; + std::tm localTime; int8_t tzOffset = 0; int8_t dstOffset = 0; -- cgit v1.2.3-70-g09d2