From 4a6241be0697bbe4ef420c43689c34af59e50330 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Sun, 21 May 2017 01:58:18 -0500 Subject: Attempt to fix #1415 OS X (and *BSD) strptime() does not set tm_wday nor tm_yday unless corresponding format options are used. That means we must call timegm() to set them. --- src/builtin.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/builtin.c b/src/builtin.c index 4ce33ca8..4ad6e173 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1228,6 +1228,8 @@ static jv f_strptime(jq_state *jq, jv a, jv b) { struct tm tm; memset(&tm, 0, sizeof(tm)); + tm.tm_wday = 8; // sentinel + tm.tm_yday = 367; // sentinel const char *input = jv_string_value(a); const char *fmt = jv_string_value(b); const char *end = strptime(input, fmt, &tm); @@ -1239,7 +1241,7 @@ static jv f_strptime(jq_state *jq, jv a, jv b) { return e; } jv_free(b); - if (tm.tm_wday == 0 && tm.tm_yday == 0 && my_mktime(&tm) == (time_t)-2) { + if ((tm.tm_wday == 8 || tm.tm_yday == 367) && my_timegm(&tm) == (time_t)-2) { jv_free(a); return jv_invalid_with_msg(jv_string("strptime/1 not supported on this platform")); } -- cgit v1.2.3