diff options
| author | JF <jf@codingfield.com> | 2022-04-02 14:34:53 (GMT) |
|---|---|---|
| committer | Gitea <gitea@fake.local> | 2022-04-02 14:34:53 (GMT) |
| commit | 187ea0f06d93c7f7df5779cb321a28ad040234ee (patch) | |
| tree | 3d6d1b2f60573045734153d975e9b0aa1b327394 /src/components/datetime/DateTimeController.cpp | |
| parent | adc7909c9823c5cd9fc9888a84e84f9182b9088f (diff) | |
| parent | b498e1d633522eed975d78b04508834b7a79befe (diff) | |
Merge branch 'develop' of JF/PineTime into master
Diffstat (limited to 'src/components/datetime/DateTimeController.cpp')
| -rw-r--r-- | src/components/datetime/DateTimeController.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 673903c..3bfbdc7 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -11,6 +11,9 @@ namespace { char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; } +DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} { +} + void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) { this->currentDateTime = t; UpdateTime(previousSystickCounter); // Update internal state without updating the time @@ -36,6 +39,8 @@ void DateTime::SetTime( UpdateTime(systickCounter); NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second); NRF_LOG_INFO("* %d %d %d ", this->day, this->month, this->year); + + systemTask->PushMessage(System::Messages::OnNewTime); } void DateTime::UpdateTime(uint32_t systickCounter) { @@ -103,11 +108,11 @@ void DateTime::UpdateTime(uint32_t systickCounter) { } } -const char* DateTime::MonthShortToString() { +const char* DateTime::MonthShortToString() const { return MonthsString[static_cast<uint8_t>(month)]; } -const char* DateTime::DayOfWeekShortToString() { +const char* DateTime::DayOfWeekShortToString() const { return DaysStringShort[static_cast<uint8_t>(dayOfWeek)]; } @@ -118,3 +123,24 @@ const char* DateTime::MonthShortToStringLow(Months month) { void DateTime::Register(Pinetime::System::SystemTask* systemTask) { this->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]; + if (settingsController.GetClockType() == ClockType::H12) { + uint8_t hour12; + const char* amPmStr; + if (hour < 12) { + hour12 = (hour == 0) ? 12 : hour; + amPmStr = "AM"; + } else { + hour12 = (hour == 12) ? 12 : hour - 12; + amPmStr = "PM"; + } + sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr); + } else { + sprintf(buff, "%02i:%02i", hour, minute); + } + return std::string(buff); +} |
