Skip to content

Commit

Permalink
Fix strflocaltime on DST values
Browse files Browse the repository at this point in the history
The following behaviour demonstrates how the daylight savings value gets
lost when a time value gets turned into an internal array of numbers and
then back into a (struct tm):

        $ TZ=Europe/London ./jq -r -n '1504803635 | strflocaltime("%Y-%m-%d %H:%M:%S (%Z)")'
        2017-09-07 18:00:35 (GMT)

After this change however, this works as expected:

        $ TZ=Europe/London ./jq -r -n '1504803635 | strflocaltime("%Y-%m-%d %H:%M:%S (%Z)")'
        2017-09-07 18:00:35 (BST)
  • Loading branch information
wjlroe committed Oct 29, 2020
1 parent a17dd32 commit d25af32
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ static jv tm2jv(struct tm *tm) {
jv_number(tm->tm_min),
jv_number(tm->tm_sec),
jv_number(tm->tm_wday),
jv_number(tm->tm_yday));
jv_number(tm->tm_yday),
jv_number(tm->tm_isdst));
}

#if defined(WIN32) && !defined(HAVE_SETENV)
Expand Down Expand Up @@ -1422,12 +1423,9 @@ static int jv2tm(jv a, struct tm *tm) {
TO_TM_FIELD(tm->tm_sec, a, 5);
TO_TM_FIELD(tm->tm_wday, a, 6);
TO_TM_FIELD(tm->tm_yday, a, 7);
TO_TM_FIELD(tm->tm_isdst, a, 8);
jv_free(a);

// We use UTC everywhere (gettimeofday, gmtime) and UTC does not do DST.
// Setting tm_isdst to 0 is done by the memset.
// tm->tm_isdst = 0;

// The standard permits the tm structure to contain additional members. We
// hope it is okay to initialize them to zero, because the standard does not
// provide an alternative.
Expand Down

0 comments on commit d25af32

Please sign in to comment.