Skip to content
Myr

Actually fix the strptime tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This has been a complicated issue to fix for a number of reasons. The core of it is that the behavior is different between different versions of macOS, some of which set possible-but-incorrect values. This commit addresses the issue by always using our computation for tm_wday and tm_yday on macOS. As a side-effect, strptime format strings that specify %u and %j will no longer work on macOS.

authored by William Langford · committed by William Langford · parent 476b367 · Browse files · 3 files+18 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−3 removed

  • tests:+3 added−2 removed
  • other:+15 added−1 removed

3 files+18 added−3 removed

modified:docs/content/3.manual/manual.yml+2 added-1 removed
1931 unmodified lines
1932 in typical C library documentation. The format string for ISO1933 8601 datetime is `"%Y-%m-%dT%H:%M:%SZ"`.19341935 jq may not support some or all of this date functionality on1936 some systems.1936 some systems. In particular, the `%u` and `%j` specifiers for1937 `strptime(fmt)` are not supported on macOS.19381939 examples:1940 - program: 'fromdate'1941 input: '"2015-03-05T23:51:47Z"'
1301 unmodified lines
modified:src/builtin.c+13 added
1311 unmodified lines
1312 * year, or a month (if tm->tm_mon == 0). But with our invalid1313 * day-of-week and day-of-year sentinel checks above, the worst1314 * this can do is produce garbage.1315 */1316#ifdef __APPLE__1317 /*1318 * Apple has made it worse, and different versions of the OS have different1319 * behaviors. Some versions just don't touch the fields, but others do, and1320 * sometimes provide wrong answers, at that! We can't tell at compile-time1321 * which behavior the target system will have, so instead we always use our1322 * functions to set these on OS X, and document that %u and %j are1323 * unsupported on OS X.1324 */1325 set_tm_wday(&tm);1326 set_tm_yday(&tm);1327#else1328 if (tm.tm_wday == 8 && tm.tm_mday != 0 && tm.tm_mon >= 0 && tm.tm_mon <= 11)1329 set_tm_wday(&tm);1330 if (tm.tm_yday == 367 && tm.tm_mday != 0 && tm.tm_mon >= 0 && tm.tm_mon <= 11)1331 set_tm_yday(&tm);1332#endif1333 jv r = tm2jv(&tm);1334 if (*end != '\0')1335 r = jv_array_append(r, jv_string(end));1336 jv_free(a); // must come after `*end` because `end` is a pointer into `a`'s string
453 unmodified lines
modified:tests/optional.test+3 added-2 removed
5 unmodified lines
6[[2015,2,5,23,51,47,4,63],1425599507]78# Check day-of-week and day of year computations9# (should trip an assert if this fails)10# This date range10last(range(365 * 199)|("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"))11last(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"))12null12[2169,0,10,1,2,3,1,9]13[2037,1,11,1,2,3,3,41]1415# %e is not available on mingw/WIN3216strftime("%A, %B %e, %Y")171435677542.822351
3 unmodified lines