Skip to content

Commit

Permalink
mktime/0: remove unnecessary length>=6 input requirement (#3162)
Browse files Browse the repository at this point in the history
This check was redundant and useless since jv2tm() used to require 8
elements, and errored anyway if not enough elements were provided.
After commit bc96146, this check also prevents mktime/0 from accepting
now supported inputs with less than 8 elements.

Ref: #3070 (comment)

Reported-by: itchyny <itchyny@cybozu.co.jp>
  • Loading branch information
emanuele6 authored Aug 21, 2024
1 parent 0e0cdd5 commit da2a0b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,6 @@ static int jv2tm(jv a, struct tm *tm) {
static jv f_mktime(jq_state *jq, jv a) {
if (jv_get_kind(a) != JV_KIND_ARRAY)
return ret_error(a, jv_string("mktime requires array inputs"));
if (jv_array_length(jv_copy(a)) < 6)
return ret_error(a, jv_string("mktime requires parsed datetime inputs"));
struct tm tm;
if (!jv2tm(a, &tm))
return jv_invalid_with_msg(jv_string("mktime requires parsed datetime inputs"));
Expand Down
4 changes: 4 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,10 @@ strftime("%Y-%m-%dT%H:%M:%SZ")
[2024,2,15]
"2024-03-15T00:00:00Z"

mktime
[2024,8,21]
1726876800

gmtime
1425599507
[2015,2,5,23,51,47,4,63]
Expand Down

0 comments on commit da2a0b9

Please sign in to comment.