Skip to content

Commit

Permalink
Switch to minutes for DST (instead of hours) to allow DST for regions…
Browse files Browse the repository at this point in the history
… with this settings
  • Loading branch information
MaxineMuster committed Jan 15, 2025
1 parent c776c29 commit 822e279
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/driver/drv_deviceclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ uint32_t RuleToTime(uint8_t dow, uint8_t mo, uint8_t week, uint8_t hr, int yr)

int8_t getDST_offset()
{
return g_DST%128; // return 0 if "unset" because -128%128 = 0
return (g_DST%128)*60; // return 0 if "unset" because -128%128 = 0
};


Expand Down Expand Up @@ -316,7 +316,7 @@ uint32_t setDST(bool setCLOCK)
// ADDLOG_INFO(LOG_FEATURE_RAW, "In second DST of %i. Info: DST ends next year at %lu (%.24s local time)\r\n",year,End_DST_epoch,ctime(&tempt));
}
}
g_ntpTime += (g_DST-old_DST)*3600*setCLOCK;
g_ntpTime += (g_DST-old_DST)*60*setCLOCK;
tempt = (time_t)next_DST_switch_epoch;

struct tm *ltm;
Expand All @@ -331,8 +331,8 @@ uint32_t setDST(bool setCLOCK)

int IsDST()
{
if (( g_DST == -128) || (g_ntpTime > next_DST_switch_epoch)) return (setDST(1)); // only in case we don't know DST status, calculate it - and while at it: set ntpTime correctly...
return (g_DST); // otherwise we can safely return the prevously calkulated value
if (( g_DST == -128) || (g_ntpTime > next_DST_switch_epoch)) return setDST(1)!=0; // only in case we don't know DST status, calculate it - and while at it: set ntpTime correctly...
return g_DST!=0; // otherwise we can safely return the prevously calculated value
}

commandResult_t CLOCK_CalcDST(const void *context, const char *cmd, const char *args, int cmdFlags) {
Expand All @@ -356,7 +356,7 @@ commandResult_t CLOCK_CalcDST(const void *context, const char *cmd, const char *
monthStart = Tokenizer_GetArgInteger(5);
dayStart = Tokenizer_GetArgInteger(6);
hourStart = Tokenizer_GetArgInteger(7);
g_DST_offset=Tokenizer_GetArgIntegerDefault(8, 1);
g_DST_offset=Tokenizer_GetArgIntegerDefault(8, 60);
ADDLOG_INFO(LOG_FEATURE_RAW, "read values: %u,%u,%u,%u,%u,%u,%u,%u,(%u)\r\n", nthWeekEnd, monthEnd, dayEnd, hourEnd, nthWeekStart, monthStart, dayStart, hourStart,g_DST_offset);

/* Start_DST_epoch = RuleToTime(dayStart,monthStart,nthWeekStart,hourStart,year);
Expand Down Expand Up @@ -394,7 +394,7 @@ void CLOCK_Init() {
CLOCK_Init_Events();
#endif
#if ENABLE_CLOCK_DST
//cmddetail:{"name":"CLOCK_CalcDST","args":"[nthWeekEnd monthEnd dayEnd hourEnd nthWeekStart monthStart dayStart hourStart [g_DSToffset hours - default is 1 if unset]",
//cmddetail:{"name":"CLOCK_CalcDST","args":"[nthWeekEnd monthEnd dayEnd hourEnd nthWeekStart monthStart dayStart hourStart [g_DSToffset minutes - default is 60 minutes if unset]",
//cmddetail:"descr":"Checks, if actual time is during DST or not.",
//cmddetail:"fn":"CLOCK_CalcDST","file":"driver/drv_ntp.c","requires":"",
//cmddetail:"examples":""}
Expand Down
12 changes: 8 additions & 4 deletions src/driver/drv_ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ commandResult_t NTP_SetTimeZoneOfs(const void *context, const char *cmd, const c
// so just to be sure, recalculate DST in any case
setDST(1); // setDST will take care of all details
#endif
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"NTP offset set"
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"NTP offset set to %i seconds"
#if ENABLE_CLOCK_DST
" - DST offset set to %i hours",getDST_offset()
" (DST offset %i seconds)"
#endif
,g_timeOffsetSeconds
#if ENABLE_CLOCK_DST
,getDST_offset()
#endif
);
return CMD_RES_OK;
Expand Down Expand Up @@ -148,7 +152,7 @@ void NTP_SetSimulatedTime(unsigned int timeNow) {
g_ntpTime = timeNow;
g_ntpTime += g_timeOffsetSeconds;
#if ENABLE_CLOCK_DST
g_ntpTime += setDST(0)*3600;
g_ntpTime += setDST(0)*60;
#endif
g_synced = true;
b_ntp_simulatedTime = true;
Expand Down Expand Up @@ -316,7 +320,7 @@ void NTP_CheckForReceive() {
g_ntpTime = secsSince1900 - NTP_OFFSET;
g_ntpTime += g_timeOffsetSeconds;
#if ENABLE_CLOCK_DST
g_ntpTime += setDST(0)*3600; // just to be sure: recalculate DST before setting, in case we somehow "moved back in time" we start with freshly set g_ntpTime, so don't change it inside setDST()!
g_ntpTime += setDST(0)*60; // just to be sure: recalculate DST before setting, in case we somehow "moved back in time" we start with freshly set g_ntpTime, so don't change it inside setDST()!
#endif
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"Unix time : %u",(unsigned int)g_ntpTime);
ltm = gmtime(&g_ntpTime);
Expand Down

0 comments on commit 822e279

Please sign in to comment.