Skip to content
Myr

Fix portability of strptime especially for Windows (#3342)

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

authored by itchyny · committed by GitHub · parent 859a807 · Browse files · 3 files+16 added−22 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+16 added−22 removed

  • tests:+15 added−16 removed
  • other:+1 added−6 removed

3 files+16 added−22 removed

modified:src/builtin.c+1 added-6 removed
1557 unmodified lines
1558 struct tm tm;1559 memset(&tm, 0, sizeof(tm));1560 tm.tm_wday = 8; // sentinel1561 tm.tm_yday = 367; // sentinel15621563 const char *input = jv_string_value(a);1564 const char *fmt = jv_string_value(b);15641565#ifndef HAVE_STRPTIME1566 if (strcmp(fmt, "%Y-%m-%dT%H:%M:%SZ")) {1567 return ret_error2(a, b, jv_string("strptime/1 only supports ISO 8601 on this platform"));1568 }1569#endif1565 const char *end = strptime(input, fmt, &tm);1566 if (end == NULL || (*end != '\0' && !isspace((unsigned char)*end))) {1567 return ret_error2(a, b, jv_string_fmt("date \"%s\" does not match format \"%s\"", input, fmt));1568 }
501 unmodified lines
modified:tests/jq.test+14 added-2 removed
1808 unmodified lines
1809try ["OK", bsearch(0)] catch ["KO",.]1810"aa"1811["KO","string (\"aa\") cannot be searched from"]18121813# strptime tests are in optional.test18141813strftime("%Y-%m-%dT%H:%M:%SZ")1814[2015,2,5,23,51,47,4,63]1815"2015-03-05T23:51:47Z"1816
34 unmodified lines
1851try ["OK", strflocaltime({})] catch ["KO", .]185201853["KO","strflocaltime/1 requires a string format"]18541855[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]1856"2015-03-05T23:51:47Z"1857[[2015,2,5,23,51,47,4,63],1425599507]18581859[strptime("%FT%T")|(.,mktime)]1860"2025-06-07T08:09:10"1861[[2025,5,7,8,9,10,6,157],1749283750]18621863# Check day-of-week and day of year computations1864# (should trip an assert if this fails)1865last(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"))1866null1867[2037,1,11,1,2,3,3,41]18681869# module system1870import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]1871null1872["a","b","c","a"]
637 unmodified lines
modified:tests/optional.test+1 added-14 removed
1# See tests/jq.test and the jq manual for more information.23# strptime() is not available on mingw/WIN324[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]5"2015-03-05T23:51:47Z"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 range11last(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"))12null13[2037,1,11,1,2,3,3,41]1415# Regression test for #32763# Regression test for #3276 (fails on mingw/WIN32)4fromdate5"2038-01-19T03:14:08Z"621474836487
1 unmodified line
9strftime("%A, %B %e, %Y")101435677542.82235111"Tuesday, June 30, 2015"1225