diff options
author | Nicolas Williams <nico@cryptonector.com> | 2017-05-21 01:58:18 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2017-05-21 01:58:18 -0500 |
commit | 4a6241be0697bbe4ef420c43689c34af59e50330 (patch) | |
tree | 0face3cc5ed698085e8693996b12d3b1748bdc65 | |
parent | 1900c7bcac76777782505c89a032c18a65fcc487 (diff) |
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.
-rw-r--r-- | src/builtin.c | 4 |
1 files changed, 3 insertions, 1 deletions
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")); } |