summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2015-06-30 08:24:26 -0700
committerDavid Tolnay <dtolnay@gmail.com>2015-07-01 20:37:16 -0700
commit6e27de4f747bc1f048aa54f3ea854f7320419e62 (patch)
tree24200191996badb5f71307d7f9038357d444f11c
parente5dafaea44b2b2ffa5cad18397d68f2b4a3c031b (diff)
strftime wrong day-of-week (fix #838)
-rw-r--r--builtin.c13
-rw-r--r--tests/jq.test4
2 files changed, 16 insertions, 1 deletions
diff --git a/builtin.c b/builtin.c
index 9d4fff1c..9ffc1db2 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1101,13 +1101,24 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
static int jv2tm(jv a, struct tm *tm) {
memset(tm, 0, sizeof(*tm));
TO_TM_FIELD(tm->tm_year, a, 0);
+ tm->tm_year -= 1900;
TO_TM_FIELD(tm->tm_mon, a, 1);
TO_TM_FIELD(tm->tm_mday, a, 2);
TO_TM_FIELD(tm->tm_hour, a, 3);
TO_TM_FIELD(tm->tm_min, a, 4);
TO_TM_FIELD(tm->tm_sec, a, 5);
- tm->tm_year -= 1900;
+ TO_TM_FIELD(tm->tm_wday, a, 6);
+ TO_TM_FIELD(tm->tm_yday, a, 7);
jv_free(a);
+
+ // We use UTC everywhere (gettimeofday, gmtime) and UTC does not do DST.
+ // Setting tm_isdst to 0 is done by the memset.
+ // tm->tm_isdst = 0;
+
+ // The standard permits the tm structure to contain additional members. We
+ // hope it is okay to initialize them to zero, because the standard does not
+ // provide an alternative.
+
return 1;
}
diff --git a/tests/jq.test b/tests/jq.test
index 30214ffa..a2c10419 100644
--- a/tests/jq.test
+++ b/tests/jq.test
@@ -1104,6 +1104,10 @@ strftime("%Y-%m-%dT%H:%M:%SZ")
[2015,2,5,23,51,47,4,63]
"2015-03-05T23:51:47Z"
+strftime("%A, %B %e, %Y")
+1435677542.822351
+"Tuesday, June 30, 2015"
+
gmtime
1425599507
[2015,2,5,23,51,47,4,63]