@ 261102.1

261102.1 · 5c001b18d7237cce1fdba63608732163f978dd23

Fix mktime/0 to allow the last two seconds of 1969 (#3671)

The mktime/0 function failed for 1969-12-31T23:59:59Z with "invalid gmtime representation", because its result -1 is also the failure value of timegm(), and for 1969-12-31T23:59:58Z with "mktime not supported on this platform", because of a leftover check for -2.

Tell a failure apart from the valid result -1 by tm_wday, which is set to -1 before the conversion and overwritten only on success, and remove the check for -2. Now `-2, -1 | gmtime | mktime` round-trip to -2 and -1, as do normalized inputs such as [1970,0,0,23,59,59,0,0], which gives -1. Inputs that the platform rejects, such as years before 1900 on macOS, still fail with "invalid gmtime representation".

reading declarations

Changes to tests/jq.test. All files

tests/jq.test

@@ -2002,6 +2002,14 @@ null null [1900,0,1,10,15,0,1,0] +[-3,-2,-1,0,1 | gmtime | mktime]+null+[-3,-2,-1,0,1]++[1970,0,0,23,59,59,0,0] | mktime+null+-1+ # Check day-of-week and day of year computations # (should trip an assert if this fails) last(range(365 * 67)|("1970-03-01T01:02:03Z"|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime) + (86400 * .)|strftime("%Y-%m-%dT%H:%M:%SZ")|strptime("%Y-%m-%dT%H:%M:%SZ"))