From 899bee2cf57b658186806dfe0a834efb921b7fc5 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:32:48 +0200 Subject: [PATCH] Exposed Month and DayOfWeek texts in DateTimeController Added static methods to return the text of a given month or dayOfWeek. --- .../datetime/DateTimeController.cpp | 44 +++++++++++++++---- src/components/datetime/DateTimeController.h | 10 ++++- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 28a70abc..0682f8f3 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -75,31 +75,59 @@ void DateTime::UpdateTime(uint32_t systickCounter) { } const char* DateTime::MonthShortToString() { - return DateTime::MonthsString[(uint8_t) month]; + return DateTime::MonthsString[static_cast(month)]; } const char* DateTime::MonthShortToStringLow() { - return DateTime::MonthsStringLow[(uint8_t) month]; + return DateTime::MonthsStringLow[static_cast(month)]; } const char* DateTime::MonthsToStringLow() { - return DateTime::MonthsLow[(uint8_t) month]; + return DateTime::MonthsLow[static_cast(month)]; } const char* DateTime::DayOfWeekToString() { - return DateTime::DaysString[(uint8_t) dayOfWeek]; + return DateTime::DaysString[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToString() { - return DateTime::DaysStringShort[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekToStringLow() { - return DateTime::DaysStringLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToStringLow() { - return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; +} + +const char* DateTime::MonthShortToString(Months month) { + return DateTime::MonthsString[static_cast(month)]; +} + +const char* DateTime::MonthShortToStringLow(Months month) { + return DateTime::MonthsStringLow[static_cast(month)]; +} + +const char* DateTime::MonthsToStringLow(Months month) { + return DateTime::MonthsLow[static_cast(month)]; +} + +const char* DateTime::DayOfWeekToString(Days dayOfWeek) { + return DateTime::DaysString[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekShortToString(Days dayOfWeek) { + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekToStringLow(Days dayOfWeek) { + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekShortToStringLow(Days dayOfWeek) { + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; } void DateTime::Register(Pinetime::System::SystemTask* systemTask) { @@ -119,4 +147,4 @@ char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; char const* DateTime::MonthsLow[] = { - "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; \ No newline at end of file + "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index 265d6e9d..66ccaa94 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -66,6 +66,14 @@ namespace Pinetime { const char* DayOfWeekToStringLow(); const char* DayOfWeekShortToStringLow(); + static const char* MonthShortToString(Months month); + static const char* MonthShortToStringLow(Months month); + static const char* MonthsToStringLow(Months month); + static const char* DayOfWeekToString(Days dayOfWeek); + static const char* DayOfWeekShortToString(Days dayOfWeek); + static const char* DayOfWeekToStringLow(Days dayOfWeek); + static const char* DayOfWeekShortToStringLow(Days dayOfWeek); + std::chrono::time_point CurrentDateTime() const { return currentDateTime; } @@ -100,4 +108,4 @@ namespace Pinetime { static char const* MonthsLow[]; }; } -} \ No newline at end of file +}