diff --git a/watch-faces/clock/world_clock_face.c b/watch-faces/clock/world_clock_face.c index 2e8db394..3bb6cbe2 100644 --- a/watch-faces/clock/world_clock_face.c +++ b/watch-faces/clock/world_clock_face.c @@ -169,7 +169,7 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, world_clo sprintf(buf, "%c%c %s", movement_valid_position_0_chars[state->settings.bit.char_0], movement_valid_position_1_chars[state->settings.bit.char_1], - (char *) (zone_names + 8 * state->settings.bit.timezone_index)); + watch_utility_time_zone_name_at_index(state->settings.bit.timezone_index)); watch_clear_indicator(WATCH_INDICATOR_PM); // blink up the parameter we're setting diff --git a/watch-faces/settings/set_time_face.c b/watch-faces/settings/set_time_face.c index c501956b..f8f7ed31 100644 --- a/watch-faces/settings/set_time_face.c +++ b/watch-faces/settings/set_time_face.c @@ -140,7 +140,7 @@ bool set_time_face_loop(movement_event_t event, void *context) { sprintf(buf, "%2d%02d ", hours % 100, minutes % 100); watch_set_colon(); } else { - sprintf(buf, "%s", (char *) (zone_names + 8 * movement_get_timezone_index())); + sprintf(buf, "%s", watch_utility_time_zone_name_at_index(movement_get_timezone_index())); watch_clear_colon(); } } else if (current_page < 4) { diff --git a/watch-library/shared/watch/watch_utility.c b/watch-library/shared/watch/watch_utility.c index b2b7fa25..013078a8 100644 --- a/watch-library/shared/watch/watch_utility.c +++ b/watch-library/shared/watch/watch_utility.c @@ -24,6 +24,7 @@ #include #include "watch_utility.h" +#include "zones.h" const char * watch_utility_get_weekday(watch_date_time_t date_time) { static const char weekdays[7][3] = {"MO", "TU", "WE", "TH", "FR", "SA", "SU"}; @@ -328,3 +329,71 @@ uint8_t watch_utility_days_in_month(uint8_t month, uint16_t year) { days += 1; return days; } + +char _scratch_timezone[7] = {0}; + +char *watch_utility_time_zone_name_at_index(int32_t tzindex) { + char *zone_in_rom = (zone_names + 8 * tzindex); + + if (watch_get_lcd_type() != WATCH_LCD_TYPE_CUSTOM) { + // classic LCD can get a pointer to ROM + return zone_in_rom; + } else { + // otherwise handle tweaks for custom LCD + strncpy(_scratch_timezone, zone_in_rom, 7); + + // D, B and T can all be displayed in position 1 + if (_scratch_timezone[0] == 'D') _scratch_timezone[0] = 'd'; + if (_scratch_timezone[0] == 'B') _scratch_timezone[0] = 'b'; + if (_scratch_timezone[0] == '+') _scratch_timezone[0] = 't'; + + // Fake M had to be lowercase before; now can be uppercase. + if (_scratch_timezone[0] == 'n' && _scratch_timezone[1] == '&') { + _scratch_timezone[0] = 'N'; + _scratch_timezone[1] = '7'; + } + + // Other edgier cases: + switch (tzindex) { + case 8: // New York + strncpy(_scratch_timezone, "NuYork", 7); + break; + case 13: // St John's + _scratch_timezone[2] = 'J'; + _scratch_timezone[3] = 'o'; + _scratch_timezone[4] = 'h'; + _scratch_timezone[5] = 'n'; + break; + case 15: // UTC + strncpy(_scratch_timezone, " UTC ", 7); + break; + case 16: // London + strncpy(_scratch_timezone, "London", 7); + break; + case 17: // Lagos + strncpy(_scratch_timezone, "Lagos ", 7); + break; + case 24: // Riyadh + strncpy(_scratch_timezone, "Riyadh", 7); + break; + case 25: // Moscow + _scratch_timezone[4] = 'O'; + _scratch_timezone[5] = 'W'; + break; + case 30: // Yangon / Burma + strncpy(_scratch_timezone, " burma", 7); + break; + case 41: // Hobart + strncpy(_scratch_timezone, "Hobart", 7); + break; + case 42: // Sydney + _scratch_timezone[2] = 'd'; + break; + case 43: // Guam + _scratch_timezone[4] = 'M'; + _scratch_timezone[5] = ' '; + break; + } + } + return _scratch_timezone; +} diff --git a/watch-library/shared/watch/watch_utility.h b/watch-library/shared/watch/watch_utility.h index 63f6a545..61c292b4 100644 --- a/watch-library/shared/watch/watch_utility.h +++ b/watch-library/shared/watch/watch_utility.h @@ -174,4 +174,9 @@ uint32_t watch_utility_offset_timestamp(uint32_t now, int8_t hours, int8_t minut */ uint8_t watch_utility_days_in_month(uint8_t month, uint16_t year); +/** @brief Returns a null-terminated six-character string representing the time zone name at a given index. + * @param tzindex The index of the time zone + */ +char * watch_utility_time_zone_name_at_index(int32_t tzindex); + #endif