]> granicus.if.org Git - jq/commitdiff
strftime wrong day-of-week (fix #838)
authorDavid Tolnay <dtolnay@gmail.com>
Tue, 30 Jun 2015 15:24:26 +0000 (08:24 -0700)
committerDavid Tolnay <dtolnay@gmail.com>
Thu, 2 Jul 2015 03:37:16 +0000 (20:37 -0700)
builtin.c
tests/jq.test

index 9d4fff1c0b9974fee3c566ecc588f1c54df2d32b..9ffc1db2cb0cec8e9abe33c95b480235d1fdb3e0 100644 (file)
--- 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;
 }
 
index 30214ffa754ced39c73b49afd4940f2c7d9fa62d..a2c104195245c63677c47bd4899dde15f7ef83b9 100644 (file)
@@ -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]