mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
c538237f4e
strptime() on OS X and *BSDs (reputedly) does not set tm_wday and tm_yday unless corresponding %U and %j format specifiers were used. That can be... surprising when one parsed year, month, and day anyways. Glibc's strptime() conveniently sets tm_wday and tm_yday in those cases, but OS X's does not, ignoring them completely. This commit makes jq compute those where possible, though the day of week computation may be wrong for dates before 1900-03-01 or after 2099-12-31.
19 lines
576 B
Plaintext
19 lines
576 B
Plaintext
# See tests/jq.test and the jq manual for more information.
|
|
|
|
# strptime() is not available on mingw/WIN32
|
|
[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
|
|
[[2015,2,5,23,51,47,4,63],1425599507]
|
|
|
|
# Check day-of-week and day of year computations
|
|
# (should trip an assert if this fails)
|
|
last(range(365 * 199)|("1900-03-01T01:02:03Z"|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime) + (86400 * .)|strftime("%Y-%m-%dT%H:%M:%SZ")|strptime("%Y-%m-%dT%H:%M:%SZ"))
|
|
null
|
|
[2099,0,10,1,2,3,6,9]
|
|
|
|
# %e is not available on mingw/WIN32
|
|
strftime("%A, %B %e, %Y")
|
|
1435677542.822351
|
|
"Tuesday, June 30, 2015"
|
|
|
|
|