File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,26 +37,30 @@ static void save_system_time_to_clocks()
3737 }
3838 else
3939 {
40- ESP_LOGI (TAG , "Time saved to the clocks: %s" , strftime_buf );
40+ ESP_LOGI (TAG , "Local time saved to the clocks: %s" , strftime_buf );
4141 }
4242}
4343
4444static void copy_time_from_clocks_to_sytem_time ()
4545{
46- struct tm time_from_clocks ;
47- if (ds3231_get_time (& timer , & time_from_clocks ) != ESP_OK )
46+ struct tm timestamp_from_clocks ;
47+ if (ds3231_get_time (& timer , & timestamp_from_clocks ) != ESP_OK )
4848 {
4949 ESP_LOGE (TAG , "Could not get time. Module is not connected or the CR2032 battery is low." );
5050 return ;
5151 }
5252
53- time_t timestamp = mktime (& time_from_clocks );
53+ // Removing daylight flag as mktime will apply it again
54+ // https://stackoverflow.com/a/68489361/2404985
55+ timestamp_from_clocks .tm_isdst = -1 ;
5456
55- ESP_LOGI (TAG , "Timestamp from clocks (secs) : %lld" , (long long )timestamp );
57+ time_t timestamp = mktime (& timestamp_from_clocks );
58+
59+ ESP_LOGI (TAG , "Local timestamp from clocks (secs) : %lld" , (long long )timestamp );
5660 struct timeval now = {
5761 .tv_sec = timestamp ,
5862 .tv_usec = 0 };
59- // The timezone was already set by main, so the second parameter is NULL
63+
6064 settimeofday (& now , NULL );
6165}
6266
You can’t perform that action at this time.
0 commit comments