From f6f427ca7df21b455a9b5f8d4dbf5a05a7590328 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sun, 8 Sep 2024 07:07:44 -0400 Subject: [PATCH 1/3] Daylight offsets now references the timezone of the destination; but it does cause an issue due to DST --- .../watch_faces/complication/sunrise_sunset_face.c | 12 +++++++++--- .../watch_faces/complication/sunrise_sunset_face.h | 7 ++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 4a3c884..29e6404 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -49,20 +49,26 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s double rise, set, minutes, seconds; bool show_next_match = false; movement_location_t movement_location; - if (state->longLatToUse == 0 || _location_count <= 1) + int16_t tz; + if (state->longLatToUse == 0 || _location_count <= 1) { movement_location = (movement_location_t) watch_get_backup_data(1); + tz = movement_timezone_offsets[settings->bit.time_zone]; + } else{ movement_location.bit.latitude = longLatPresets[state->longLatToUse].latitude; movement_location.bit.longitude = longLatPresets[state->longLatToUse].longitude; + tz = movement_timezone_offsets[longLatPresets[state->longLatToUse].timezone]; } if (movement_location.reg == 0) { + watch_clear_all_indicators(); + watch_clear_colon(); watch_display_string("RI no Loc", 0); return; } watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time - watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, state->tz * 60, 0); // the current date / time in UTC + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC watch_date_time scratch_time; // scratchpad, contains different values at different times scratch_time.reg = utc_now.reg; @@ -77,7 +83,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s // sunriset returns the rise/set times as signed decimal hours in UTC. // this can mean hours below 0 or above 31, which won't fit into a watch_date_time struct. // to deal with this, we set aside the offset in hours, and add it back before converting it to a watch_date_time. - double hours_from_utc = ((double)state->tz) / 60.0; + double hours_from_utc = ((double)tz) / 60.0; // we loop twice because if it's after sunset today, we need to recalculate to display values for tomorrow. for(int i = 0; i < 2; i++) { diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h index f216a2f..429253e 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.h +++ b/movement/watch_faces/complication/sunrise_sunset_face.h @@ -76,14 +76,15 @@ typedef struct { char name[2]; int16_t latitude; int16_t longitude; + int16_t timezone; // References element in movement_timezone_offsets } long_lat_presets_t; static const long_lat_presets_t longLatPresets[] = { { .name = " "}, // Default, the long and lat get replaced by what's set in the watch -// { .name = "Ny", .latitude = 4072, .longitude = -7401 }, // New York City, NY -// { .name = "LA", .latitude = 3405, .longitude = -11824 }, // Los Angeles, CA -// { .name = "dE", .latitude = 4221, .longitude = -8305 }, // Detroit, MI + { .name = "Ny", .latitude = 4072, .longitude = -7401, .timezone = 35 }, // New York City, NY + { .name = "LA", .latitude = 3405, .longitude = -11824, .timezone = 30 }, // Los Angeles, CA + { .name = "dE", .latitude = 4221, .longitude = -8305, .timezone = 35 }, // Detroit, MI }; #endif // SUNRISE_SUNSET_FACE_H_ From 0d16329574a18f7ba8cbf9e8705d9c5b60b8fa3f Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sun, 8 Sep 2024 09:03:43 -0400 Subject: [PATCH 2/3] Sunrise sunset face now warns about using DST --- .../complication/sunrise_sunset_face.c | 15 +++++++++------ .../complication/sunrise_sunset_face.h | 12 +++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 29e6404..a436776 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -57,7 +57,10 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s else{ movement_location.bit.latitude = longLatPresets[state->longLatToUse].latitude; movement_location.bit.longitude = longLatPresets[state->longLatToUse].longitude; - tz = movement_timezone_offsets[longLatPresets[state->longLatToUse].timezone]; + if (longLatPresets[state->longLatToUse].timezone == SUNRISE_USE_LOCAL_TZ) + tz = movement_timezone_offsets[settings->bit.time_zone]; + else + tz = movement_timezone_offsets[longLatPresets[state->longLatToUse].timezone]; } if (movement_location.reg == 0) { @@ -405,11 +408,11 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti break; case EVENT_ALARM_LONG_PRESS: if (state->page == 0) { - if (state->longLatToUse != 0) { - state->longLatToUse = 0; - _sunrise_sunset_face_update(settings, state); - break; - } + if (state->longLatToUse != 0) { + state->longLatToUse = 0; + _sunrise_sunset_face_update(settings, state); + break; + } state->page++; state->active_digit = 0; watch_clear_display(); diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h index 429253e..537fc51 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.h +++ b/movement/watch_faces/complication/sunrise_sunset_face.h @@ -59,6 +59,8 @@ typedef struct { uint8_t longLatToUse; } sunrise_sunset_state_t; +#define SUNRISE_USE_LOCAL_TZ 0xFF + void sunrise_sunset_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); void sunrise_sunset_face_activate(movement_settings_t *settings, void *context); bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context); @@ -76,15 +78,15 @@ typedef struct { char name[2]; int16_t latitude; int16_t longitude; - int16_t timezone; // References element in movement_timezone_offsets + uint8_t timezone; // References element in movement_timezone_offsets; Set to 0xFF to use local timezone } long_lat_presets_t; +// Locations must either use the same timezone as local time, or not observe DST. static const long_lat_presets_t longLatPresets[] = { - { .name = " "}, // Default, the long and lat get replaced by what's set in the watch - { .name = "Ny", .latitude = 4072, .longitude = -7401, .timezone = 35 }, // New York City, NY - { .name = "LA", .latitude = 3405, .longitude = -11824, .timezone = 30 }, // Los Angeles, CA - { .name = "dE", .latitude = 4221, .longitude = -8305, .timezone = 35 }, // Detroit, MI + { .name = " "}, // Default, the long, lat, and timezone get replaced by what's set in the watch +// { .name = "dE", .latitude = 4221, .longitude = -8305, .timezone = SUNRISE_USE_LOCAL_TZ }, // Detroit, MI; Assumes you live in the Eastern Timezone +// { .name = "To", .latitude = 3567, .longitude = 13965, .timezone = 15 }, // Tokyo, JP }; #endif // SUNRISE_SUNSET_FACE_H_ From 9d1410780c34e990757164976a2e3e3f64643699 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sun, 8 Sep 2024 10:37:36 -0400 Subject: [PATCH 3/3] sunrise sunset fix during DST --- .../watch_faces/complication/sunrise_sunset_face.c | 9 ++++----- .../watch_faces/complication/sunrise_sunset_face.h | 10 ++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index a436776..4c77fe5 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -50,15 +50,16 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s bool show_next_match = false; movement_location_t movement_location; int16_t tz; + watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time if (state->longLatToUse == 0 || _location_count <= 1) { + tz = get_timezone_offset(settings->bit.time_zone, date_time); movement_location = (movement_location_t) watch_get_backup_data(1); - tz = movement_timezone_offsets[settings->bit.time_zone]; } else{ movement_location.bit.latitude = longLatPresets[state->longLatToUse].latitude; movement_location.bit.longitude = longLatPresets[state->longLatToUse].longitude; - if (longLatPresets[state->longLatToUse].timezone == SUNRISE_USE_LOCAL_TZ) - tz = movement_timezone_offsets[settings->bit.time_zone]; + if (longLatPresets[state->longLatToUse].uses_dst && dst_occurring(date_time)) + tz = movement_timezone_dst_offsets[longLatPresets[state->longLatToUse].timezone]; else tz = movement_timezone_offsets[longLatPresets[state->longLatToUse].timezone]; } @@ -70,7 +71,6 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s return; } - watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC watch_date_time scratch_time; // scratchpad, contains different values at different times scratch_time.reg = utc_now.reg; @@ -343,7 +343,6 @@ void sunrise_sunset_face_activate(movement_settings_t *settings, void *context) movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude); state->working_longitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.longitude); - state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time()); } bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h index 537fc51..d100dd4 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.h +++ b/movement/watch_faces/complication/sunrise_sunset_face.h @@ -52,7 +52,6 @@ typedef struct { uint8_t rise_index; uint8_t active_digit; bool location_changed; - int16_t tz; watch_date_time rise_set_expires; sunrise_sunset_lat_lon_settings_t working_latitude; sunrise_sunset_lat_lon_settings_t working_longitude; @@ -78,15 +77,18 @@ typedef struct { char name[2]; int16_t latitude; int16_t longitude; - uint8_t timezone; // References element in movement_timezone_offsets; Set to 0xFF to use local timezone + uint8_t timezone; // References element in movement_timezone_offsets + bool uses_dst; } long_lat_presets_t; // Locations must either use the same timezone as local time, or not observe DST. static const long_lat_presets_t longLatPresets[] = { { .name = " "}, // Default, the long, lat, and timezone get replaced by what's set in the watch -// { .name = "dE", .latitude = 4221, .longitude = -8305, .timezone = SUNRISE_USE_LOCAL_TZ }, // Detroit, MI; Assumes you live in the Eastern Timezone -// { .name = "To", .latitude = 3567, .longitude = 13965, .timezone = 15 }, // Tokyo, JP +// { .name = "Ny", .latitude = 4072, .longitude = -7401, .timezone = 33, .uses_dst = true }, // New York City, NY +// { .name = "LA", .latitude = 3405, .longitude = -11824, .timezone = 30, .uses_dst = true }, // Los Angeles, CA +// { .name = "dE", .latitude = 4221, .longitude = -8305, .timezone = 33, .uses_dst = true }, // Detroit, MI +// { .name = "To", .latitude = 3567, .longitude = 13965, .timezone = 15, .uses_dst = false }, // Tokyo, JP }; #endif // SUNRISE_SUNSET_FACE_H_