MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / formatTime

Method formatTime

lib/hal/HalClock.cpp:103–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103bool HalClock::formatTime(char* buf, size_t bufSize, uint8_t utcOffsetQuarterHoursBiased, bool use12Hour) const {
104 if (bufSize < (use12Hour ? 9u : 6u)) return false;
105 uint8_t h, m;
106 if (!getTime(h, m)) return false;
107
108 // Apply UTC offset: convert biased value to signed quarter-hours.
109 // Clamp against corrupted persisted values so display time can't drift outside [-12:00, +14:00].
110 if (utcOffsetQuarterHoursBiased > 104) utcOffsetQuarterHoursBiased = 104;
111 int offsetQuarterHours = static_cast<int>(utcOffsetQuarterHoursBiased) - 48;
112 int totalMinutes = static_cast<int>(h) * 60 + static_cast<int>(m) + offsetQuarterHours * 15;
113
114 // Wrap around 24 hours
115 totalMinutes = ((totalMinutes % 1440) + 1440) % 1440;
116
117 const int hour24 = totalMinutes / 60;
118 const int min = totalMinutes % 60;
119 if (use12Hour) {
120 const bool pm = hour24 >= 12;
121 int hour12 = hour24 % 12;
122 if (hour12 == 0) hour12 = 12;
123 snprintf(buf, bufSize, "%d:%02d %s", hour12, min, pm ? "PM" : "AM");
124 } else {
125 snprintf(buf, bufSize, "%02d:%02d", hour24, min);
126 }
127 return true;
128}
129
130bool HalClock::writeTimeToRTC(uint8_t hour, uint8_t minute, uint8_t second) {
131 assert(hour < 24);

Callers 3

drawStatusBarMethod · 0.80
runSyncMethod · 0.80
renderMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected