···3344// A header-only implementation of a Pebble clock module that displays the
55// IATA code of a randomly-chosen airport whose local time is the *closest past
66-//* but not before* 12:00:00 (noon) relative to the current UTC. The
66+// but not before* 12:00:00 (noon) relative to the current UTC. The
77// underlying data come from the generated `airport_tz_list.c`, which is built
88// by `generate_airport_tz_list.py`.
99//
···205205206206 // Update text layers ---------------------------------------------------
207207 text_layer_set_text(code_layer, s_selected_code);
208208-209208 long offset_seconds = (long)(s_selected_offset_hours * 3600.0f);
210210- time_t local_epoch = current_utc_t + offset_seconds;
211211- struct tm *local_tm = gmtime(&local_epoch);
212212-209209+ // Compute local time using utc_tm and offset to avoid second gmtime()
210210+ long total_local_secs = (utc_tm->tm_hour * 3600L + utc_tm->tm_min * 60L + utc_tm->tm_sec + offset_seconds) % DAY_SECONDS;
211211+ if (total_local_secs < 0) total_local_secs += DAY_SECONDS;
212212+ int local_min = (int)((total_local_secs / 60) % 60);
213213+ int local_sec = (int)(total_local_secs % 60);
213214 static char s_timebuf[10];
214214- if (local_tm) {
215215- snprintf(s_timebuf, sizeof(s_timebuf), "%02d:%02d", local_tm->tm_min, local_tm->tm_sec);
216216- } else {
217217- snprintf(s_timebuf, sizeof(s_timebuf), "ERR");
218218- }
215215+ snprintf(s_timebuf, sizeof(s_timebuf), "%02d:%02d", local_min, local_sec);
219216 text_layer_set_text(time_layer, s_timebuf);
220217}
221218···224221#endif
225222226223#endif /* CLOCK_CLOSEST_AIRPORT_NOON_H */
227227-228228-// Note: using airport_name_offsets[] directly for name lookup