Skip to content

Commit 7cc202a

Browse files
authored
Fix portability of strptime especially for Windows (#3342)
1 parent 859a807 commit 7cc202a

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

src/builtin.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,14 +1559,9 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
15591559
memset(&tm, 0, sizeof(tm));
15601560
tm.tm_wday = 8; // sentinel
15611561
tm.tm_yday = 367; // sentinel
1562+
15621563
const char *input = jv_string_value(a);
15631564
const char *fmt = jv_string_value(b);
1564-
1565-
#ifndef HAVE_STRPTIME
1566-
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-
#endif
15701565
const char *end = strptime(input, fmt, &tm);
15711566
if (end == NULL || (*end != '\0' && !isspace((unsigned char)*end))) {
15721567
return ret_error2(a, b, jv_string_fmt("date \"%s\" does not match format \"%s\"", input, fmt));

tests/jq.test

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,8 +1810,6 @@ try ["OK", bsearch(0)] catch ["KO",.]
18101810
"aa"
18111811
["KO","string (\"aa\") cannot be searched from"]
18121812

1813-
# strptime tests are in optional.test
1814-
18151813
strftime("%Y-%m-%dT%H:%M:%SZ")
18161814
[2015,2,5,23,51,47,4,63]
18171815
"2015-03-05T23:51:47Z"
@@ -1854,6 +1852,20 @@ try ["OK", strflocaltime({})] catch ["KO", .]
18541852
0
18551853
["KO","strflocaltime/1 requires a string format"]
18561854

1855+
[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
1856+
"2015-03-05T23:51:47Z"
1857+
[[2015,2,5,23,51,47,4,63],1425599507]
1858+
1859+
[strptime("%FT%T")|(.,mktime)]
1860+
"2025-06-07T08:09:10"
1861+
[[2025,5,7,8,9,10,6,157],1749283750]
1862+
1863+
# Check day-of-week and day of year computations
1864+
# (should trip an assert if this fails)
1865+
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"))
1866+
null
1867+
[2037,1,11,1,2,3,3,41]
1868+
18571869
# module system
18581870
import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]
18591871
null

tests/optional.test

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
# See tests/jq.test and the jq manual for more information.
22

3-
# strptime() is not available on mingw/WIN32
4-
[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
5-
"2015-03-05T23:51:47Z"
6-
[[2015,2,5,23,51,47,4,63],1425599507]
7-
8-
# Check day-of-week and day of year computations
9-
# (should trip an assert if this fails)
10-
# This date range
11-
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"))
12-
null
13-
[2037,1,11,1,2,3,3,41]
14-
15-
# Regression test for #3276
3+
# Regression test for #3276 (fails on mingw/WIN32)
164
fromdate
175
"2038-01-19T03:14:08Z"
186
2147483648
@@ -22,4 +10,3 @@ strftime("%A, %B %e, %Y")
2210
1435677542.822351
2311
"Tuesday, June 30, 2015"
2412

25-

0 commit comments

Comments
 (0)