]> git.earman.xyz Git - sensor-watch.git/commitdiff
Revert PR #470 - implement automatic DST toggling
authorMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Tue, 17 Sep 2024 20:08:32 +0000 (17:08 -0300)
committerMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Tue, 17 Sep 2024 20:28:32 +0000 (17:28 -0300)
The DST code has not yet been fully tested, the upcoming movement
refactor is upon us and it will integrate with the micro timezone
library anyway. Revert it so that next can be merged into main.

This reverts commit ac5bf8cfce67cdb5662aeea618c2eb9511f0d190, reversing
changes made to 5a8a49a8c77d6d5ba0f46f0e5b51dec2daba46db.

32 files changed:
movement/movement.c
movement/movement.h
movement/movement_config.h
movement/watch_faces/clock/beats_face.c
movement/watch_faces/clock/day_night_percentage_face.c
movement/watch_faces/clock/mars_time_face.c
movement/watch_faces/clock/world_clock2_face.c
movement/watch_faces/clock/world_clock2_face.h
movement/watch_faces/clock/world_clock_face.c
movement/watch_faces/clock/world_clock_face.h
movement/watch_faces/complication/astronomy_face.c
movement/watch_faces/complication/countdown_face.c
movement/watch_faces/complication/moon_phase_face.c
movement/watch_faces/complication/orrery_face.c
movement/watch_faces/complication/planetary_hours_face.c
movement/watch_faces/complication/planetary_time_face.c
movement/watch_faces/complication/sailing_face.c
movement/watch_faces/complication/solstice_face.c
movement/watch_faces/complication/sunrise_sunset_face.c
movement/watch_faces/complication/sunrise_sunset_face.h
movement/watch_faces/complication/timer_face.c
movement/watch_faces/complication/tomato_face.c
movement/watch_faces/complication/totp_face.c
movement/watch_faces/complication/totp_face_lfs.c
movement/watch_faces/sensor/accelerometer_data_acquisition_face.c
movement/watch_faces/settings/set_time_face.c
movement/watch_faces/settings/set_time_hackwatch_face.c
watch-library/hardware/watch/watch_rtc.c
watch-library/shared/watch/watch_rtc.h
watch-library/shared/watch/watch_utility.c
watch-library/shared/watch/watch_utility.h
watch-library/simulator/watch/watch_rtc.c

index a8a22bdf92780c3db6b4bc7981d8cbed3af47926..2ea43fade6363e0b623ccfa41092c16c4fbb2f54 100644 (file)
@@ -34,7 +34,6 @@
 #include "filesystem.h"
 #include "movement.h"
 #include "shell.h"
-#include "watch_utility.h"
 
 #ifndef MOVEMENT_FIRMWARE
 #include "movement_config.h"
 #define MOVEMENT_DEFAULT_LED_DURATION 1
 #endif
 
-// Default to having DST get set
-#ifndef MOVEMENT_DEFAULT_DST_ACTIVE
-#define MOVEMENT_DEFAULT_DST_ACTIVE true
-#endif
-
 #if __EMSCRIPTEN__
 #include <emscripten.h>
 #endif
@@ -112,8 +106,7 @@ const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 600, 3600, 7200, 2
 const int16_t movement_timeout_inactivity_deadlines[4] = {60, 120, 300, 1800};
 movement_event_t event;
 
-#define NUM_TIME_ZONES 41
-const int16_t movement_timezone_offsets[NUM_TIME_ZONES] = {
+const int16_t movement_timezone_offsets[] = {
     0,      //  0 :   0:00:00 (UTC)
     60,     //  1 :   1:00:00 (Central European Time)
     120,    //  2 :   2:00:00 (South African Standard Time)
@@ -170,50 +163,94 @@ const int16_t movement_timezone_offsets[NUM_TIME_ZONES] = {
  * having to separately change the hour and timezone info
  * in the time set face.
  */
-const int16_t movement_timezone_dst_offsets[NUM_TIME_ZONES] = {
-    60,  // 0  UTC  + 1 = CET
-    120,  // 1  CET  + 1 = SAST
-    189,  // 2  SAST + 1 = AST
-    240,  // 3  AST  + 1 = GST
-    270,  // 4  IST  + 1 = AT
-    300,  // 5  GST  + 1 = PST
-    330,  // 6  AT   + 1 = IST
-    360, // 7  PST  + 1 = KT
-    390, // 8  IST  + 1 = MT
-    345,  // 9  Nepal has no equivalent DST timezone, but they don't observe DST anyway
-    420, // 10 KT   + 1 = TST
-    390, // 11 Myanmar has no equivalent DST timezone, but they don't observe DST anyway
-    480, // 12 TST  + 1 = CST
-    540, // 13 CST  + 1 = JST
-    525, // 14 ACWST has no equivalent DST timezone, but they don't observe DST anyway
-    600, // 15 JST  + 1 = AEST
-    630, // 16 ACST + 1 = LHST
-    660, // 17 AEST + 1 = SIT
-    630, // 18 LHST has no equivalent DST timezone, but they don't observe DST anyway
-    720, // 19 SIT  + 1 = NZST
-    780, // 20 NZST + 1 = TT
-    825, // 21 CST  + 1 = CDT
-    840, // 22 TT   + 1 = LIT
-    825, // 23 CDT is already a daylight timezone
-    840, // 24 LIT has no equivalent DST timezone, but they don't observe DST anyway
-    -660, // 25 BIT  + 1 = NT
-    -600, // 26 NT   + 1 = HAST
-    -540, // 27 HAST + 1 = AST
-    -570, // 28 MIT has no equivalent DST timezone, but they don't observe DST anyway
-    -480, // 29 AST  + 1 = PST
-    -420, // 30 PST  + 1 = MST
-    -360, // 31 MST  + 1 = CST
-    -300, // 32 CST  + 1 = EST
-    -240, // 33 EST  + 1 = AST
-    -210, // 34 VST  + 1 = NST
-    -180, // 35 AST  + 1 = BT
-    -150, // 36 NST  + 1 = NDT
-    -120, // 37 BT   + 1 = 39
-    -150, // 38 NDT is already a daylight timezone
-    -60, // 39 FNT  + 1 = AST
+const uint8_t movement_dst_jump_table[] = {
+    1,  // 0  UTC  + 1 = CET
+    2,  // 1  CET  + 1 = SAST
+    3,  // 2  SAST + 1 = AST
+    5,  // 3  AST  + 1 = GST
+    6,  // 4  IST  + 1 = AT
+    7,  // 5  GST  + 1 = PST
+    8,  // 6  AT   + 1 = IST
+    10, // 7  PST  + 1 = KT
+    11, // 8  IST  + 1 = MT
+    9,  // 9  Nepal has no equivalent DST timezone, but they don't observe DST anyway
+    12, // 10 KT   + 1 = TST
+    11, // 11 Myanmar has no equivalent DST timezone, but they don't observe DST anyway
+    13, // 12 TST  + 1 = CST
+    15, // 13 CST  + 1 = JST
+    14, // 14 ACWST has no equivalent DST timezone, but they don't observe DST anyway
+    17, // 15 JST  + 1 = AEST
+    18, // 16 ACST + 1 = LHST
+    19, // 17 AEST + 1 = SIT
+    18, // 18 LHST has no equivalent DST timezone, but they don't observe DST anyway
+    20, // 19 SIT  + 1 = NZST
+    22, // 20 NZST + 1 = TT
+    23, // 21 CST  + 1 = CDT
+    24, // 22 TT   + 1 = LIT
+    23, // 23 CDT is already a daylight timezone
+    24, // 24 LIT has no equivalent DST timezone, but they don't observe DST anyway
+    26, // 25 BIT  + 1 = NT
+    27, // 26 NT   + 1 = HAST
+    29, // 27 HAST + 1 = AST
+    28, // 28 MIT has no equivalent DST timezone, but they don't observe DST anyway
+    30, // 29 AST  + 1 = PST
+    31, // 30 PST  + 1 = MST
+    32, // 31 MST  + 1 = CST
+    33, // 32 CST  + 1 = EST
+    35, // 33 EST  + 1 = AST
+    36, // 34 VST  + 1 = NST
+    37, // 35 AST  + 1 = BT
+    38, // 36 NST  + 1 = NDT
+    39, // 37 BT   + 1 = 39
+    38, // 38 NDT is already a daylight timezone
+    40, // 39 FNT  + 1 = AST
     0   // 40 AST  + 1 = UTC
 };
 
+const uint8_t movement_dst_inverse_jump_table[] = {
+    40, // 0
+    0,  // 1
+    1,  // 2
+    2,  // 3
+    4,  // 4
+    3,  // 5
+    4,  // 6
+    5,  // 7
+    6,  // 8
+    9,  // 9
+    7,  // 10
+    8,  // 11
+    10, // 12
+    12, // 13
+    14, // 14
+    13, // 15
+    16, // 16
+    15, // 17
+    16, // 18
+    17, // 19
+    19, // 20
+    21, // 21
+    20, // 22
+    21, // 23
+    24, // 24
+    25, // 25
+    25, // 26
+    26, // 27
+    28, // 28
+    27, // 29
+    29, // 30
+    30, // 31
+    31, // 32
+    32, // 33
+    34, // 34
+    33, // 35
+    34, // 36
+    35, // 37
+    36, // 38
+    37, // 39
+    39  // 40
+};
+
 const char movement_valid_position_0_chars[] = " AaBbCcDdEeFGgHhIiJKLMNnOoPQrSTtUuWXYZ-='+\\/0123456789";
 const char movement_valid_position_1_chars[] = " ABCDEFHlJLNORTtUX-='01378";
 
@@ -247,31 +284,6 @@ static inline void _movement_disable_fast_tick_if_possible(void) {
     }
 }
 
-static bool _check_and_act_on_daylight_savings(void) {
-    if (!movement_state.settings.bit.dst_active) return false;
-    watch_date_time date_time = watch_rtc_get_date_time();
-    // No need for all of the unix time calculations for times not at the beginning or end of the hour
-    if (date_time.unit.minute > 1 && date_time.unit.minute < 59) return false;
-    uint8_t dst_result = get_dst_status(date_time);
-    bool dst_skip_rolling_back = get_dst_skip_rolling_back();
-
-    if (dst_skip_rolling_back && (dst_result == DST_ENDED)) {
-        clear_dst_skip_rolling_back();
-    }
-    else if (dst_result == DST_ENDING && !dst_skip_rolling_back) {
-        date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
-        watch_rtc_set_date_time(date_time);
-        set_dst_skip_rolling_back();
-        return true;
-    }
-    else if (dst_result == DST_STARTING) {
-        date_time.unit.hour = (date_time.unit.hour + 1) % 24;
-        watch_rtc_set_date_time(date_time);
-        return true;
-    }
-    return false;
-}
-
 static void _movement_handle_background_tasks(void) {
     for(uint8_t i = 0; i < MOVEMENT_NUM_FACES; i++) {
         // For each face, if the watch face wants a background task...
@@ -281,7 +293,6 @@ static void _movement_handle_background_tasks(void) {
             watch_faces[i].loop(background_event, &movement_state.settings, watch_face_contexts[i]);
         }
     }
-    _check_and_act_on_daylight_savings();
     movement_state.needs_background_tasks_handled = false;
 }
 
@@ -479,12 +490,6 @@ uint8_t movement_claim_backup_register(void) {
     return movement_state.next_available_backup_register++;
 }
 
-int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time) {
-    if (movement_state.settings.bit.dst_active && dst_occurring(date_time))
-        return movement_timezone_dst_offsets[timezone_idx];
-    return movement_timezone_offsets[timezone_idx];
-}
-
 void app_init(void) {
 #if defined(NO_FREQCORR)
     watch_rtc_freqcorr_write(0, 0);
@@ -502,19 +507,6 @@ void app_init(void) {
     movement_state.settings.bit.to_interval = MOVEMENT_DEFAULT_TIMEOUT_INTERVAL;
     movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL;
     movement_state.settings.bit.led_duration = MOVEMENT_DEFAULT_LED_DURATION;
-    movement_state.settings.bit.dst_active = MOVEMENT_DEFAULT_DST_ACTIVE;
-
-#ifdef MAKEFILE_TIMEZONE
-    timezone_offsets = dst_occurring(watch_rtc_get_date_time()) ? movement_timezone_dst_offsets : movement_timezone_offsets;
-    for (int i = 0; i < NUM_TIME_ZONES; i++) {
-        if (timezone_offsets[i] == MAKEFILE_TIMEZONE) {
-            movement_state.settings.bit.time_zone = i;
-            break;
-        }
-    }
-#else
-    movement_state.settings.bit.time_zone = 35;  // Atlantic Time as default
-#endif
 
     movement_state.light_ticks = -1;
     movement_state.alarm_ticks = -1;
@@ -524,13 +516,11 @@ void app_init(void) {
     filesystem_init();
 
 #if __EMSCRIPTEN__
-    const int16_t* timezone_offsets;
     int32_t time_zone_offset = EM_ASM_INT({
         return -new Date().getTimezoneOffset();
     });
-    timezone_offsets = dst_occurring(watch_rtc_get_date_time()) ? movement_timezone_dst_offsets : movement_timezone_offsets;
-    for (int i = 0; i < NUM_TIME_ZONES; i++) {
-        if (timezone_offsets[i] == time_zone_offset) {
+    for (int i = 0, count = sizeof(movement_timezone_offsets) / sizeof(movement_timezone_offsets[0]); i < count; i++) {
+        if (movement_timezone_offsets[i] == time_zone_offset) {
             movement_state.settings.bit.time_zone = i;
             break;
         }
index 46be32fde81f7ab9870ecbf7a1bd162d38bb0b91..ecf5d8bd921fbf492b26b80d39a626321f20f9bb 100644 (file)
@@ -130,7 +130,8 @@ typedef struct {
 } movement_event_t;
 
 extern const int16_t movement_timezone_offsets[];
-extern const int16_t movement_timezone_dst_offsets[];
+extern const uint8_t movement_dst_jump_table[];
+extern const uint8_t movement_dst_inverse_jump_table[];
 extern const char movement_valid_position_0_chars[];
 extern const char movement_valid_position_1_chars[];
 
@@ -314,6 +315,5 @@ void movement_play_alarm(void);
 void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
 
 uint8_t movement_claim_backup_register(void);
-int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time);
 
 #endif // MOVEMENT_H_
index 46e1d2e4ef00946c56ebb2fe754afe34f3f8811c..10a30af77309f73dea3cd43ed8bc2870e2c0b583 100644 (file)
@@ -95,11 +95,4 @@ const watch_face_t watch_faces[] = {
  */
 #define MOVEMENT_DEFAULT_LED_DURATION 1
 
-/* Set if using DST
- * Valid values are:
- * false: Don't allow the watch to use DST
- * true: Allow the watch to use DST
- */
-#define MOVEMENT_DEFAULT_DST_ACTIVE true
-
 #endif // MOVEMENT_CONFIG_H_
index 6954396884d07c9e55dbf43f5ee80d5a43ffeb9e..85bcbe08ae34379c9b386af09b44f0e40179e5bc 100644 (file)
@@ -61,7 +61,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void
         case EVENT_ACTIVATE:
         case EVENT_TICK:
             date_time = watch_rtc_get_date_time();
-            centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, get_timezone_offset(settings->bit.time_zone, date_time));
+            centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]);
             if (centibeats == state->last_centibeat_displayed) {
                 // we missed this update, try again next subsecond
                 state->next_subsecond_update = (event.subsecond + 1) % BEAT_REFRESH_FREQUENCY;
@@ -76,7 +76,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void
         case EVENT_LOW_ENERGY_UPDATE:
             if (!watch_tick_animation_is_running()) watch_start_tick_animation(432);
             date_time = watch_rtc_get_date_time();
-            centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, get_timezone_offset(settings->bit.time_zone, date_time));
+            centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]);
             sprintf(buf, "bt  %4lu  ", centibeats / 100);
 
             watch_display_string(buf, 0);
index 4041c058d2aadc89e662c98c28a3aea9f1494a2c..86f07f9d339e4871486cb75c54961113bbcd85bb 100644 (file)
@@ -62,8 +62,7 @@ void day_night_percentage_face_setup(movement_settings_t *settings, uint8_t watc
     if (*context_ptr == NULL) {
         *context_ptr = malloc(sizeof(day_night_percentage_state_t));
         day_night_percentage_state_t *state = (day_night_percentage_state_t *)*context_ptr;
-        watch_date_time date_time = watch_rtc_get_date_time();
-        watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60, 0);
+        watch_date_time utc_now = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
         recalculate(utc_now, state);
     }
 }
@@ -78,7 +77,7 @@ bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t
 
     char buf[12];
     watch_date_time date_time = watch_rtc_get_date_time();
-    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60, 0);
+    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
 
     switch (event.event_type) {
         case EVENT_ACTIVATE:
index 304c615b2d47dfe256113ee405b61c3427e4ad09..30f6a34b02bb0714932f664f75b9dba1c2e6c6a4 100644 (file)
@@ -70,7 +70,7 @@ static void _h_to_hms(mars_clock_hms_t *date_time, double h) {
 static void _update(movement_settings_t *settings, mars_time_state_t *state) {
     char buf[11];
     watch_date_time date_time = watch_rtc_get_date_time();
-    uint32_t now = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
+    uint32_t now = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
     // TODO: I'm skipping over some steps here.
     // https://www.giss.nasa.gov/tools/mars24/help/algorithm.html
     double jdut = 2440587.5 + ((double)now / 86400.0);
index 09bda4297912b482d45dd20cf4644526b6eccafb..4d50552f2c45bc28765b86bc7f7a594798dd567d 100644 (file)
@@ -154,7 +154,6 @@ void world_clock2_face_activate(movement_settings_t *settings, void *context)
             movement_request_tick_frequency(4);
             break;
     }
-    state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time());
     refresh_face = true;
 }
 
@@ -184,8 +183,8 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
 
             /* Determine current time at time zone and store date/time */
            date_time = watch_rtc_get_date_time();
-        timestamp = watch_utility_date_time_to_unix_time(date_time, state->tz * 60);
-           date_time = watch_utility_date_time_from_unix_time(timestamp, state->tz_curr * 60);
+           timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
+           date_time = watch_utility_date_time_from_unix_time(timestamp, movement_timezone_offsets[state->current_zone] * 60);
            previous_date_time = state->previous_date_time;
            state->previous_date_time = date_time.reg;
 
@@ -292,7 +291,7 @@ static bool mode_settings(movement_event_t event, movement_settings_t *settings,
                 watch_clear_indicator(WATCH_INDICATOR_PM);
                 refresh_face = false;
             }
-           result = div(state->tz_curr, 60);
+           result = div(movement_timezone_offsets[state->current_zone], 60);
            hours = result.quot;
            minutes = result.rem;
 
index 5d8310fff444347c567970479f2520bc74746f71..0baac2123b17c453f4c1150d24d37a82cb8abbc8 100644 (file)
@@ -104,8 +104,6 @@ typedef struct {
     world_clock2_mode_t current_mode;
     uint8_t current_zone;
     uint32_t previous_date_time;
-    int16_t tz;
-    int16_t tz_curr;
 } world_clock2_state_t;
 
 void world_clock2_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void **context_ptr);
index 80f4ebf4b285c27b6e6917d599fbefc3980f662c..c324b5f0a5aefbe13c7bda46bbe18aae292dfaac 100644 (file)
@@ -60,16 +60,15 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
     watch_date_time date_time;
     switch (event.event_type) {
         case EVENT_ACTIVATE:
-            state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time());
-            if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
+            if (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);
             watch_set_colon();
             state->previous_date_time = 0xFFFFFFFF;
             // fall through
         case EVENT_TICK:
         case EVENT_LOW_ENERGY_UPDATE:
             date_time = watch_rtc_get_date_time();
-            timestamp = watch_utility_date_time_to_unix_time(date_time, state->tz * 60);
-            date_time = watch_utility_date_time_from_unix_time(timestamp, state->tz_curr * 60);
+            timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
+            date_time = watch_utility_date_time_from_unix_time(timestamp, movement_timezone_offsets[state->settings.bit.timezone_index] * 60);
             previous_date_time = state->previous_date_time;
             state->previous_date_time = date_time.reg;
 
@@ -178,8 +177,8 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_
     sprintf(buf, "%c%c %3d%02d  ",
         movement_valid_position_0_chars[state->settings.bit.char_0],
         movement_valid_position_1_chars[state->settings.bit.char_1],
-        (int8_t) (state->tz_curr / 60),
-        (int8_t) (state->tz_curr % 60) * (state->tz_curr < 0 ? -1 : 1));
+        (int8_t) (movement_timezone_offsets[state->settings.bit.timezone_index] / 60),
+        (int8_t) (movement_timezone_offsets[state->settings.bit.timezone_index] % 60) * (movement_timezone_offsets[state->settings.bit.timezone_index] < 0 ? -1 : 1));
     watch_set_colon();
     watch_clear_indicator(WATCH_INDICATOR_PM);
 
index 2de3ceda28263668be11b073e019673ae4702573..92e91a6ff28bc63f71f0457ecc466c2045bf2bfa 100644 (file)
@@ -62,8 +62,6 @@ typedef struct {
     uint8_t backup_register;
     uint8_t current_screen;
     uint32_t previous_date_time;
-    int16_t tz;
-    int16_t tz_curr;
 } world_clock_state_t;
 
 void world_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
index 8db8760c738abda5878dc167e16cb1848e5372f3..204a0a3a70509c84ed3503671ac322ab3efebae6 100644 (file)
@@ -80,7 +80,7 @@ static void _astronomy_face_recalculate(movement_settings_t *settings, astronomy
 #endif
 
     watch_date_time date_time = watch_rtc_get_date_time();
-    uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
+    uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
     date_time = watch_utility_date_time_from_unix_time(timestamp, 0);
     double jd = astro_convert_date_to_julian_date(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
 
index 825595e88dd12a9fbb85d52eebe488d257f091e2..f585ebc39c94f4ce15d22f0fe04ca8aa3ab3ed43 100644 (file)
@@ -45,8 +45,8 @@ static void abort_quick_ticks(countdown_state_t *state) {
     }
 }
 
-static inline int32_t get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
-    return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
+static inline int32_t get_tz_offset(movement_settings_t *settings) {
+    return movement_timezone_offsets[settings->bit.time_zone] * 60;
 }
 
 static inline void store_countdown(countdown_state_t *state) {
@@ -70,15 +70,13 @@ static inline void button_beep(movement_settings_t *settings) {
 }
 
 static void schedule_countdown(countdown_state_t *state, movement_settings_t *settings) {
-    watch_date_time now = watch_rtc_get_date_time();
-    int16_t tz = get_tz_offset(settings, now);
 
-    // Calculate the new state->now_ts but don't update it until we've updated the target -
+    // Calculate the new state->now_ts but don't update it until we've updated the target - 
     // avoid possible race where the old target is compared to the new time and immediately triggers
-    uint32_t new_now = watch_utility_date_time_to_unix_time(now, tz);
+    uint32_t new_now = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), get_tz_offset(settings));
     state->target_ts = watch_utility_offset_timestamp(new_now, state->hours, state->minutes, state->seconds);
     state->now_ts = new_now;
-    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, tz);
+    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
     movement_schedule_background_task_for_face(state->watch_face_index, target_dt);
 }
 
@@ -205,7 +203,7 @@ void countdown_face_activate(movement_settings_t *settings, void *context) {
     countdown_state_t *state = (countdown_state_t *)context;
     if(state->mode == cd_running) {
         watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
+        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
         watch_set_indicator(WATCH_INDICATOR_SIGNAL);
     }
     watch_set_colon();
index c5718434e221902235583cecf818c8e35e6d3e18..f74de647c68cc344a53982bff9571e8829c9bfea 100644 (file)
@@ -59,9 +59,8 @@ static void _update(movement_settings_t *settings, moon_phase_state_t *state, ui
     (void)state;
     char buf[11];
     watch_date_time date_time = watch_rtc_get_date_time();
-    int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time);
-    uint32_t now = watch_utility_date_time_to_unix_time(date_time, tz * 60) + offset;
-    date_time = watch_utility_date_time_from_unix_time(now, tz * 60);
+    uint32_t now = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60) + offset;
+    date_time = watch_utility_date_time_from_unix_time(now, movement_timezone_offsets[settings->bit.time_zone] * 60);
     double currentfrac = fmod(now - FIRST_MOON, LUNAR_SECONDS) / LUNAR_SECONDS;
     double currentday = currentfrac * LUNAR_DAYS;
     uint8_t phase_index = 0;
@@ -139,7 +138,6 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
 
     switch (event.event_type) {
         case EVENT_ACTIVATE:
-        
             _update(settings, state, state->offset);
             break;
         case EVENT_TICK:
index 0570dd40b1a71ca48afa2b71285c887ab119de0e..42fdf81f56e01a4d3444eda3ed69537051b24779 100644 (file)
@@ -48,7 +48,7 @@ static const char orrery_celestial_body_names[NUM_AVAILABLE_BODIES][3] = {
 
 static void _orrery_face_recalculate(movement_settings_t *settings, orrery_state_t *state) {
     watch_date_time date_time = watch_rtc_get_date_time();
-    uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
+    uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
     date_time = watch_utility_date_time_from_unix_time(timestamp, 0);
     double jd = astro_convert_date_to_julian_date(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
     double et = astro_convert_jd_to_julian_millenia_since_j2000(jd);
index e0c0a15c169121ee1af4039007e203c1d2e94eee..e13466b120cd5cfd9685540d08d04594731c8537 100644 (file)
@@ -134,8 +134,7 @@ static void _planetary_solar_phases(movement_settings_t *settings, planetary_hou
     state->no_location = false;
 
     watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
-    int16_t tz = get_timezone_offset(settings->bit.time_zone, 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 utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
     watch_date_time scratch_time; // scratchpad, contains different values at different times
     watch_date_time midnight;
     scratch_time.reg = midnight.reg = utc_now.reg;
@@ -148,7 +147,7 @@ static void _planetary_solar_phases(movement_settings_t *settings, planetary_hou
     double lon = (double)lon_centi / 100.0;
 
     // save UTC offset
-    state->utc_offset = ((double)tz) / 60.0;
+    state->utc_offset = ((double)movement_timezone_offsets[settings->bit.time_zone]) / 60.0;
 
     // calculate sunrise and sunset of current day in decimal hours after midnight
     sun_rise_set(scratch_time.unit.year + WATCH_RTC_REFERENCE_YEAR, scratch_time.unit.month, scratch_time.unit.day, lon, lat, &sunrise, &sunset);
@@ -239,7 +238,7 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat
 
     // get current time
     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, get_timezone_offset(settings->bit.time_zone, date_time) * 60, 0); // the current date / time in UTC
+    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
     current_hour_epoch = watch_utility_date_time_to_unix_time(utc_now, 0);
     
     // set the current planetary hour as default screen
index 1245cc6162261bb4d9f8d8601dd60c2aa86c922c..7e7ac6c7db1faede660dcf53b9b6ebf330addc91 100644 (file)
@@ -37,7 +37,7 @@
 // STATIC FUNCTIONS AND CONSTANTS /////////////////////////////////////////////
 
 /** @brief Planetary rulers in the Chaldean order from slowest to fastest
- *  @details Planetary rulers in the Chaldean order from slowest to fastest:
+ *  @details Planetary rulers in the Chaldean order from slowest to fastest: 
  *  Jupiter, Mars, Sun, Venus, Mercury, Moon
  */
 static const char planets[7][3] = {"Sa", "Ju", "Ma", "So", "Ve", "Me", "Lu"}; // Latin
@@ -129,8 +129,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
     state->no_location = false;
 
     watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
-    int16_t tz = get_timezone_offset(settings->bit.time_zone, 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 utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
     watch_date_time scratch_time; // scratchpad, contains different values at different times
     watch_date_time midnight;
     scratch_time.reg = midnight.reg = utc_now.reg;
@@ -143,7 +142,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
     double lon = (double)lon_centi / 100.0;
 
     // save UTC offset
-    state->utc_offset = ((double)tz) / 60.0;
+    state->utc_offset = ((double)movement_timezone_offsets[settings->bit.time_zone]) / 60.0;
 
     // get UNIX epoch time
     now_epoch = watch_utility_date_time_to_unix_time(utc_now, 0);
@@ -151,7 +150,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
 
     // calculate sunrise and sunset of current day in decimal hours after midnight
     sun_rise_set(scratch_time.unit.year + WATCH_RTC_REFERENCE_YEAR, scratch_time.unit.month, scratch_time.unit.day, lon, lat, &sunrise, &sunset);
-
+    
     // calculate sunrise and sunset UNIX timestamps
     sunrise_epoch = midnight_epoch + sunrise * 3600;
     sunset_epoch = midnight_epoch + sunset * 3600;
@@ -192,7 +191,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
         state->phase_end = sunrise_epoch;
     }
 
-    // calculate the duration of a planetary second during this solar phase
+    // calculate the duration of a planetary second during this solar phase 
     // and convert to Hertz so we can call a faster tick rate
     state->freq = (1 / ((double)( state->phase_end - state->phase_start ) / 43200));
 }
@@ -208,12 +207,11 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
     uint8_t weekday, planet, planetary_hour;
     double hour_duration, current_hour, current_minute, current_second;
     bool set_leading_zero = false;
-    watch_date_time date_time = watch_rtc_get_date_time();
 
         watch_set_colon();
 
     // get current time and convert to UTC
-    state->scratch = watch_utility_date_time_convert_zone(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60, 0);
+    state->scratch = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60, 0); 
 
     // when current phase ends calculate the next phase
     if ( watch_utility_date_time_to_unix_time(state->scratch, 0) >= state->phase_end ) {
@@ -263,11 +261,11 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
     if ( state->ruler == 0 ) strncpy(ruler, planets[planet], 3);
     if ( state->ruler == 1 ) strncpy(ruler, planetes[planet], 3);
     if ( state->ruler == 2 ) strncpy(ruler, "  ", 3);
-
+    
     // display planetary time with ruler of the hour or ruler of the day
     if ( state->day_ruler ) sprintf(buf, "%s d%2d%02d%02d", ruler, state->scratch.unit.hour, state->scratch.unit.minute, state->scratch.unit.second);
     else sprintf(buf, "%s h%2d%02d%02d", ruler, state->scratch.unit.hour, state->scratch.unit.minute, state->scratch.unit.second);
-
+    
     watch_display_string(buf, 0);
     if (set_leading_zero)
         watch_display_string("0", 4);
@@ -303,7 +301,7 @@ void planetary_time_face_activate(movement_settings_t *settings, void *context)
 #endif
 
     planetary_time_state_t *state = (planetary_time_state_t *)context;
-
+    
     // calculate phase
     _planetary_solar_phase(settings, state);
 }
index 16d60c91f89bc55b26ff807c266163d6ec56f0ca..a6c13fe8621357b711c06859cd647f90031accac 100644 (file)
@@ -33,8 +33,8 @@
 #define sl_SELECTIONS 6
 #define DEFAULT_MINUTES { 5,4,1,0,0,0 }
 
-static inline int32_t get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
-    return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
+static inline int32_t get_tz_offset(movement_settings_t *settings) {
+    return movement_timezone_offsets[settings->bit.time_zone] * 60;
 }
 
 static int lap = 0;
@@ -165,8 +165,7 @@ static void ring(sailing_state_t *state, movement_settings_t *settings) {
         return;
     }
     state->nextbeep_ts = state->target_ts - beepseconds[beepflag+1];
-    watch_date_time now = watch_rtc_get_date_time();
-    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->nextbeep_ts, get_tz_offset(settings, now));
+    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->nextbeep_ts, get_tz_offset(settings));
     movement_schedule_background_task_for_face(state->watch_face_index, target_dt);
 //background task is set, now we have time to play the tune. If this is cancelled accidentally, the next alarm will still ring. Sound is implemented non-blocking, so that neither buttons nor display output are compromised.
     for (int i = 0; i < 5; i++) {
@@ -195,7 +194,7 @@ static void start(sailing_state_t *state, movement_settings_t *settings) {//gets
     }
     if (state->index > 5 || state->minutes[state->index] == 0) {
         watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
+        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
         state->target_ts = state->now_ts;
         if (alarmflag != 0){
             watch_buzzer_play_sequence(long_beep, NULL);
@@ -206,7 +205,7 @@ static void start(sailing_state_t *state, movement_settings_t *settings) {//gets
     movement_request_tick_frequency(1); //synchronises tick with the moment the button was pressed. Solves 1s offset between sound and display, solves up to +-0.5s offset between button action and display.
     state->mode = sl_running;
     watch_date_time now = watch_rtc_get_date_time();
-    state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
+    state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
     state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, state->minutes[state->index], 0);
     ring(state, settings);
 }
@@ -254,11 +253,11 @@ void sailing_face_activate(movement_settings_t *settings, void *context) {
     sailing_state_t *state = (sailing_state_t *)context;
     if(state->mode == sl_running) {
         watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
+        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
     }
     if(state->mode == sl_counting) {
         watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
+        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
         watch_set_indicator(WATCH_INDICATOR_LAP);
     }
     switch (alarmflag) {
index 76d0d26ee4874a83df97c210984a6025c6b2ae18..e74f8789d160501e205b36ccd65a1bca76dc135b 100644 (file)
@@ -123,10 +123,9 @@ static watch_date_time jde_to_date_time(double JDE) {
 }
 
 static void calculate_datetimes(solstice_state_t *state, movement_settings_t *settings) {
-    watch_date_time date_time = watch_rtc_get_date_time();
     for (int i = 0; i < 4; i++) {
         // TODO: handle DST changes
-        state->datetimes[i] = jde_to_date_time(calculate_solstice_equinox(2020 + state->year, i) + (get_timezone_offset(settings->bit.time_zone, date_time) / (60.0*24.0)));
+        state->datetimes[i] = jde_to_date_time(calculate_solstice_equinox(2020 + state->year, i) + (movement_timezone_offsets[settings->bit.time_zone] / (60.0*24.0)));
     }
 }
 
index 4a3c88433b83dff0f0ba362a8fc85695bcd641f6..8747bd868ef414efa3b9ec82fb1d008f0961d670 100644 (file)
@@ -62,7 +62,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
     }
 
     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, movement_timezone_offsets[settings->bit.time_zone] * 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 +77,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)movement_timezone_offsets[settings->bit.time_zone]) / 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++) {
@@ -334,7 +334,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) {
index f216a2ffd6019dd0419a03c3d4f0f87c168fddd0..df5fda5c128e4c2407889737c4b5d166dfa29672 100644 (file)
@@ -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;
index 5ee2967b16db690500e50b85e15ea3bdacfa303a..29392d694152e9f4845a949252ffb8d971730fe7 100644 (file)
@@ -36,8 +36,8 @@ static const int8_t _sound_seq_start[] = {BUZZER_NOTE_C8, 2, 0};
 
 static uint8_t _beeps_to_play;    // temporary counter for ring signals playing
 
-static inline int32_t _get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
-    return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
+static inline int32_t _get_tz_offset(movement_settings_t *settings) {
+    return movement_timezone_offsets[settings->bit.time_zone] * 60;
 }
 
 static void _signal_callback() {
@@ -50,8 +50,7 @@ static void _signal_callback() {
 static void _start(timer_state_t *state, movement_settings_t *settings, bool with_beep) {
     if (state->timers[state->current_timer].value == 0) return;
     watch_date_time now = watch_rtc_get_date_time();
-    int32_t tz = _get_tz_offset(settings, now);
-    state->now_ts = watch_utility_date_time_to_unix_time(now, tz);
+    state->now_ts = watch_utility_date_time_to_unix_time(now, _get_tz_offset(settings));
     if (state->mode == pausing)
         state->target_ts = state->now_ts + state->paused_left;
     else
@@ -59,7 +58,7 @@ static void _start(timer_state_t *state, movement_settings_t *settings, bool wit
                                                           state->timers[state->current_timer].unit.hours, 
                                                           state->timers[state->current_timer].unit.minutes, 
                                                           state->timers[state->current_timer].unit.seconds);
-    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, tz);
+    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, _get_tz_offset(settings));
     state->mode = running;
     movement_schedule_background_task_for_face(state->watch_face_index, target_dt);
     watch_set_indicator(WATCH_INDICATOR_BELL);
@@ -211,7 +210,7 @@ void timer_face_activate(movement_settings_t *settings, void *context) {
     watch_set_colon();
     if(state->mode == running) {
         watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, _get_tz_offset(settings, now));
+        state->now_ts = watch_utility_date_time_to_unix_time(now, _get_tz_offset(settings));
         watch_set_indicator(WATCH_INDICATOR_BELL);
     } else {
         state->pausing_seconds = 1;
index 15b67c62b4042a576b56e6f5e4c4bd4c1c999f8e..3d46ba94c7035dfbc5569675c2fae4ca391e39b1 100644 (file)
@@ -30,8 +30,8 @@
 static uint8_t focus_min = 25;
 static uint8_t break_min = 5;
 
-static inline int32_t get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
-    return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
+static inline int32_t get_tz_offset(movement_settings_t *settings) {
+    return movement_timezone_offsets[settings->bit.time_zone] * 60;
 }
 
 static uint8_t get_length(tomato_state_t *state) {
@@ -47,13 +47,12 @@ static uint8_t get_length(tomato_state_t *state) {
 
 static void tomato_start(tomato_state_t *state, movement_settings_t *settings) {
     watch_date_time now = watch_rtc_get_date_time();
-    int32_t tz = get_tz_offset(settings, now);
     int8_t length = (int8_t) get_length(state);
 
     state->mode = tomato_run;
-    state->now_ts = watch_utility_date_time_to_unix_time(now, tz);
+    state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
     state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, length, 0);
-    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, tz);
+    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
     movement_schedule_background_task(target_dt);
     watch_set_indicator(WATCH_INDICATOR_BELL);
 }
@@ -127,7 +126,7 @@ void tomato_face_activate(movement_settings_t *settings, void *context) {
     tomato_state_t *state = (tomato_state_t *)context;
     if (state->mode == tomato_run) {
         watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
+        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
         watch_set_indicator(WATCH_INDICATOR_BELL);
     }
     watch_set_colon();
index c5b26f2c8d13d49bbff1dbe1e444d93648683805..fdb410959ef43fd498b53dd63318020b17b06927 100644 (file)
@@ -157,9 +157,8 @@ static void totp_generate_and_display(totp_state_t *totp_state) {
     totp_display(totp_state);
 }
 
-static uint32_t totp_compute_base_timestamp(movement_settings_t *settings) {
-    watch_date_time date_time = watch_rtc_get_date_time();
-    return watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
+static inline uint32_t totp_compute_base_timestamp(movement_settings_t *settings) {
+    return watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
 }
 
 void totp_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
index 1319d47afd107096d74eb583f120b70db985a069..5d7defe88e26bde2545ea91dfa2c8fea30de9d41 100644 (file)
@@ -254,8 +254,7 @@ void totp_face_lfs_activate(movement_settings_t *settings, void *context) {
     }
 #endif
 
-    watch_date_time date_time = watch_rtc_get_date_time();
-    totp_state->timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
+    totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
     totp_face_set_record(totp_state, 0);
 }
 
index 9cadf671abd5db2e4cece91a2d98e517d83f40bf..6d174d5a667bf89f84f807c8a7fde3b10379a804 100644 (file)
@@ -442,7 +442,7 @@ static void start_reading(accelerometer_data_acquisition_state_t *state, movemen
 
     accelerometer_data_acquisition_record_t record;
     watch_date_time date_time = watch_rtc_get_date_time();
-    state->starting_timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
+    state->starting_timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
     record.header.info.record_type = ACCELEROMETER_DATA_ACQUISITION_HEADER;
     record.header.info.range = ACCELEROMETER_RANGE;
     record.header.info.temperature = lis2dw_get_temperature();
index 0b7057557fc232b2cbab9ec9d8abdc77451c4cf1..d50d24be01c11da0671cc41493dee77baecbb713 100644 (file)
@@ -60,6 +60,13 @@ static void _handle_alarm_button(movement_settings_t *settings, watch_date_time
             if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
             break;
         case 7: // daylight savings time
+            if (settings->bit.dst_active) {  // deactivate DST
+                date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
+                settings->bit.time_zone = movement_dst_inverse_jump_table[settings->bit.time_zone];
+            } else {  // activate DST
+                date_time.unit.hour = (date_time.unit.hour + 1) % 24;
+                settings->bit.time_zone = movement_dst_jump_table[settings->bit.time_zone];
+            }
             settings->bit.dst_active = !settings->bit.dst_active;
             break;
     }
@@ -128,9 +135,8 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
             return movement_default_loop_handler(event, settings);
     }
 
-    char buf[13];
+    char buf[11];
     bool set_leading_zero = false;
-
     if (current_page < 3) {
         watch_set_colon();
         if (settings->bit.clock_mode_24h) {
@@ -150,18 +156,17 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
         watch_clear_indicator(WATCH_INDICATOR_PM);
         sprintf(buf, "%s  %2d%02d%02d", set_time_face_titles[current_page], date_time.unit.year + 20, date_time.unit.month, date_time.unit.day);
     } else if (current_page < 7) {  // zone
-        char dst_char = (settings->bit.dst_active && dst_occurring(watch_rtc_get_date_time())) ? 'd' : ' ';
         if (event.subsecond % 2) {
             watch_clear_colon();
-            sprintf(buf, "%s       %c", set_time_face_titles[current_page], dst_char);
+            sprintf(buf, "%s        ", set_time_face_titles[current_page]);
         } else {
-            int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time);
             watch_set_colon();
-            sprintf(buf, "%s %3d%02d %c", set_time_face_titles[current_page], (int8_t) (tz / 60), (int8_t) (tz % 60) * (tz < 0 ? -1 : 1), dst_char);
+            sprintf(buf, "%s %3d%02d  ", set_time_face_titles[current_page], (int8_t) (movement_timezone_offsets[settings->bit.time_zone] / 60), (int8_t) (movement_timezone_offsets[settings->bit.time_zone] % 60) * (movement_timezone_offsets[settings->bit.time_zone] < 0 ? -1 : 1));
         }
     } else { // daylight savings
         watch_clear_colon();
-        sprintf(buf, "%s   dsT %c", set_time_face_titles[current_page], settings->bit.dst_active ? 'y' : 'n');
+        if (settings->bit.dst_active) sprintf(buf, "%s   dsT y", set_time_face_titles[current_page]);
+        else sprintf(buf, "%s   dsT n", set_time_face_titles[current_page]);
     }
 
     // blink up the parameter we're setting
index 6e67808d45b1cbe77889c262ac6c5a5a07b61b0a..75bc7bb46070b019f6871615309e7906548b2bf6 100644 (file)
@@ -132,9 +132,8 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
                     }
                     break;
             }
-            if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
+            if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
                 watch_rtc_set_date_time(date_time_settings);
-            }
             break;
 
         case EVENT_ALARM_LONG_UP://Setting seconds on long release
@@ -172,16 +171,11 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
                     if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
                     break;
             }
-
             if (date_time_settings.unit.day > days_in_month(date_time_settings.unit.month, date_time_settings.unit.year + WATCH_RTC_REFERENCE_YEAR))
                 date_time_settings.unit.day = 1;
-
-            if (current_page != 2) { // Do not set time when we are at seconds, it was already set previously
+            if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
                 watch_rtc_set_date_time(date_time_settings);
-            }
-
             //TODO: Do not update whole RTC, just what we are changing
-
             break;
         case EVENT_TIMEOUT:
             movement_move_to_face(0);
@@ -237,13 +231,12 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
             watch_clear_colon();
             sprintf(buf, "%s        ", set_time_hackwatch_face_titles[current_page]);
         } else {
-            int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time_settings);
             watch_set_colon();
             sprintf(buf,
                     "%s %3d%02d  ",
                     set_time_hackwatch_face_titles[current_page],
-                    (int8_t)(tz / 60),
-                    (int8_t)(tz % 60) * (tz < 0 ? -1 : 1));
+                    (int8_t)(movement_timezone_offsets[settings->bit.time_zone] / 60),
+                    (int8_t)(movement_timezone_offsets[settings->bit.time_zone] % 60) * (movement_timezone_offsets[settings->bit.time_zone] < 0 ? -1 : 1));
         }
     }
 
index 67ecb5315dfaeb9b589183118d8c207834ecbd1a..93cb9f1cfb6e30c9d67e66d26a61eda3d46afc04 100644 (file)
@@ -30,19 +30,6 @@ ext_irq_cb_t btn_alarm_callback;
 ext_irq_cb_t a2_callback;
 ext_irq_cb_t a4_callback;
 
-static bool dst_skip_rolling_back;
-bool get_dst_skip_rolling_back(void) {
-    return dst_skip_rolling_back;
-}
-
-void set_dst_skip_rolling_back(void) {
-    dst_skip_rolling_back = true;
-}
-
-void clear_dst_skip_rolling_back(void) {
-    dst_skip_rolling_back = false;
-}
-
 bool _watch_rtc_is_enabled(void) {
     return RTC->MODE2.CTRLA.bit.ENABLE;
 }
@@ -73,7 +60,6 @@ void watch_rtc_set_date_time(watch_date_time date_time) {
     _sync_rtc(); // Double sync as without it at high Hz faces setting time is unrealiable (specifically, set_time_hackwatch)
     RTC->MODE2.CLOCK.reg = date_time.reg;
     _sync_rtc();
-    clear_dst_skip_rolling_back();
 }
 
 watch_date_time watch_rtc_get_date_time(void) {
index a9134eb281b58dc6f55700622fff56f09ebda75e..3e63bb55893f856bed19751094bd88ad8d0bc9dd 100644 (file)
@@ -157,11 +157,5 @@ void watch_rtc_enable(bool en);
   */
 void watch_rtc_freqcorr_write(int16_t value, int16_t sign);
 
-/** @brief Returns if we're currently at a point where the we rolled back for DST and need to ignore the next DST segment
-  */
-bool get_dst_skip_rolling_back(void);
-void set_dst_skip_rolling_back(void);
-void clear_dst_skip_rolling_back(void);
-
 /// @}
 #endif
index a7db6585c541a6891aff9c780aad53f4f40b6d36..c00791e76786605634d3c5b343e570a88f75bffc 100644 (file)
@@ -83,44 +83,6 @@ uint8_t is_leap(uint16_t y)
        return !(y%4) && ((y%100) || !(y%400));
 }
 
-uint8_t get_dst_status(watch_date_time date_time) {
-    watch_date_time dst_start_time;
-    watch_date_time dst_end_time;
-    uint32_t unix_dst_start_time;
-    uint32_t unix_dst_end_time;
-    uint32_t unix_curr_time;
-
-    dst_start_time.unit.year = date_time.unit.year;
-    dst_start_time.unit.month = 3;
-    dst_start_time.unit.hour = 2;
-    dst_start_time.unit.minute = 0;
-    dst_start_time.unit.second = 0;
-    dst_start_time.unit.day = 15 - watch_utility_get_iso8601_weekday_number(dst_start_time.unit.year + WATCH_RTC_REFERENCE_YEAR, dst_start_time.unit.month, 1);
-    unix_dst_start_time = watch_utility_date_time_to_unix_time(dst_start_time, 0);
-
-    dst_end_time.unit.year = date_time.unit.year;
-    dst_end_time.unit.month = 11;
-    dst_end_time.unit.hour = 2;
-    dst_end_time.unit.minute = 0;
-    dst_end_time.unit.second = 0;
-    dst_end_time.unit.day = 15 - watch_utility_get_iso8601_weekday_number(dst_end_time.unit.year + WATCH_RTC_REFERENCE_YEAR, dst_end_time.unit.month, 1);
-    unix_dst_end_time = watch_utility_date_time_to_unix_time(dst_end_time, 0);
-
-    unix_curr_time = watch_utility_date_time_to_unix_time(date_time, 0);
-    unix_curr_time -= date_time.unit.second;
-    if (date_time.unit.second > 45)  // In emu, it's been seen that we may trigger at 59sec rather than exactly 0 each time
-        unix_curr_time += 60;
-
-    if (unix_curr_time == unix_dst_start_time) return DST_STARTING;
-    if (unix_curr_time == unix_dst_end_time) return DST_ENDING;
-    if (unix_curr_time > unix_dst_end_time || unix_curr_time < unix_dst_start_time) return DST_ENDED;
-    return DST_OCCURRING;
-}
-
-bool dst_occurring(watch_date_time date_time) {
-    return get_dst_status(date_time) <= DST_OCCURRING;
-}
-
 uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t day) {
     uint16_t DAYS_SO_FAR[] = {
         0,   // Jan
index 12ee8d2b3bf495ed0b755d3300a89da349e0cba9..5533e19661c4d9dda1883f545e2bca448cb0f4a5 100644 (file)
@@ -45,13 +45,6 @@ typedef struct {
     uint32_t days;    // 0-4294967295
 } watch_duration_t;
 
-typedef enum {
-    DST_STARTING,
-    DST_OCCURRING,
-    DST_ENDING,
-    DST_ENDED
-} dst_t;
-
 /** @brief Returns a two-letter weekday for the given timestamp, suitable for display
   *        in positions 0-1 of the watch face
   * @param date_time The watch_date_time whose weekday you want.
@@ -85,17 +78,6 @@ uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t
  */
 uint8_t is_leap(uint16_t year);
 
-/** @brief Returns off of dst_t based off if DST is occurring, srted, ended, or none of those.
- * @param date_time The watch_date_time that you wish to convert.
- * @return DST_OCCURRING, DST_HAPPENING, DST_ENDING, DST_ENDED
- */
-uint8_t get_dst_status(watch_date_time date_time);
-
-/** @brief Returns true if it's DST and false otherwise.
- * @param date_time The watch_date_time that you wish to convert.
- */
-bool dst_occurring(watch_date_time date_time);
-
 /** @brief Returns the UNIX time (seconds since 1970) for a given date/time in UTC.
   * @param date_time The watch_date_time that you wish to convert.
   * @param year The year of the date you wish to convert.
index 9fe9e2965cd5cd5efa7e71683688473f275f11b1..2bb6074c714ceda61f6c6e94fa01f77cbff6d194 100644 (file)
@@ -39,19 +39,6 @@ ext_irq_cb_t btn_alarm_callback;
 ext_irq_cb_t a2_callback;
 ext_irq_cb_t a4_callback;
 
-static bool dst_skip_rolling_back;
-bool get_dst_skip_rolling_back(void) {
-    return dst_skip_rolling_back;
-}
-
-void set_dst_skip_rolling_back(void) {
-    dst_skip_rolling_back = true;
-}
-
-void clear_dst_skip_rolling_back(void) {
-    dst_skip_rolling_back = false;
-}
-
 bool _watch_rtc_is_enabled(void) {
     return true;
 }
@@ -70,7 +57,6 @@ void watch_rtc_set_date_time(watch_date_time date_time) {
         const date = new Date(year, month - 1, day, hour, minute, second);
         return date - Date.now();
     }, date_time.reg);
-    clear_dst_skip_rolling_back();
 }
 
 watch_date_time watch_rtc_get_date_time(void) {