Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clock: Fix DST problem in [clock scan] using "-gmt 0" #299

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

prpr19xx
Copy link
Contributor

Currently (in the UK, pre-DST, with "now" set to 1711500000):

. clock scan {2024-03-31 00:00:00} -format {%F %T} -gmt 0	;# Correct
1711843200
. clock scan {2024-03-31 00:00:00} -format {%F %T} -gmt 1	;# Correct
1711843200

. clock scan {2024-04-01 00:00:00} -format {%F %T} -gmt 0	;# Wrong
1711929600
. clock scan {2024-04-01 00:00:00} -format {%F %T} -gmt 1	;# Correct
1711929600

Next week (post-DST, with "now" set to 1712000000):

. clock scan {2024-03-31 00:00:00} -format {%F %T} -gmt 0	;# Wrong
1711839600
. clock scan {2024-03-31 00:00:00} -format {%F %T} -gmt 1	;# Correct
1711843200

. clock scan {2024-04-01 00:00:00} -format {%F %T} -gmt 0	;# Correct
1711926000
. clock scan {2024-04-01 00:00:00} -format {%F %T} -gmt 1	;# Correct
1711929600

This because tm.tm_isdst is set by localtime_r() using "now" set by time(NULL).
It is nonsensical to specify a date to convert and have the DST flag used in the conversion set from another (i.e. the current) date.

With the patch (set tm.tm_isdst to -1 and leave mktime() to figure it out), it is correct under all circumstances:

. clock scan {2024-03-31 00:00:00} -format {%F %T} -gmt 0	;# Correct
1711843200
. clock scan {2024-03-31 00:00:00} -format {%F %T} -gmt 1	;# Correct
1711843200

. clock scan {2024-04-01 00:00:00} -format {%F %T} -gmt 0	;# Correct
1711926000
. clock scan {2024-04-01 00:00:00} -format {%F %T} -gmt 1	;# Correct
1711929600

For reference:

. clock format 1711839600 -format {%F %T %Z} -gmt 1
2024-03-30 23:00:00 GMT

. clock format 1711843200 -format {%F %T %Z} -gmt 1
2024-03-31 00:00:00 GMT

. clock format 1711926000 -format {%F %T %Z} -gmt 1
2024-03-31 23:00:00 GMT

. clock format 1711929600 -format {%F %T %Z} -gmt 1
2024-04-01 00:00:00 GMT

@msteveb msteveb merged commit 161aad1 into msteveb:master Mar 29, 2024
4 checks passed
@msteveb
Copy link
Owner

msteveb commented Mar 29, 2024

LGTM. Thx

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants