Skip to content

Commit

Permalink
Attempt to fix jqlang#1415
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicowilliams authored and davidfetter committed Aug 9, 2017
1 parent 750ea5e commit 6639aaa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"));
}
Expand Down

0 comments on commit 6639aaa

Please # to comment.