Skip to content

Commit

Permalink
Run tzset() and localtime() in getTZOffset() to ensure proper timezon…
Browse files Browse the repository at this point in the history
…e offset
  • Loading branch information
jp-bennett committed May 31, 2024
1 parent 10e3040 commit 7e81375
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/gps/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ bool perhapsSetRTC(RTCQuality q, struct tm &t)
*/
int32_t getTZOffset()
{
tzset();
time_t now;
struct tm *gmt;
struct tm *local;
now = time(NULL);
gmt = gmtime(&now);
gmt->tm_isdst = -1;
return (int32_t)difftime(now, mktime(gmt));
local = localtime(&now);
return (int32_t)difftime(mktime(local), mktime(gmt));
}

/**
Expand Down Expand Up @@ -265,4 +267,4 @@ time_t gm_mktime(struct tm *tm)
setenv("TZ", "UTC0", 1);
}
return res;
}
}

0 comments on commit 7e81375

Please sign in to comment.