Using jq-1.5 from https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
AFAIK, fractional seconds are valid ISO8601.
jq: error (at <stdin>:1180): date "2016-03-17T17:06:59.764Z" does not match format "%Y-%m-%dT%H:%M:%SZ"
I don't care about the milliseconds, perhaps some people do. That's a harder problem, since you output in an int. But for people who don't care, perhaps you can make a fromdate variant that drops the milliseconds.
The workaround for now for me is:
| sub(".[0-9]+Z$"; "Z") | fromdate
Thanks for the workaround! This helps parsing Bunyan log records. I use a slightly altered regex to make sure it's a literal dot:
| sub("\\.[0-9]+Z$"; "Z") | fromdate
This is especially annoying as JSON.stringify produces these strings (e.g. JSON.stringify({now: new Date()}) => {now: "2017-11-08T01:00:36.383Z"} which are annoying to parse with jq.
To parse iso8601 dates with timezone offset (#1053 ) and fractional seconds, this should work :
sub("\\.[0-9]+\\+"; "+") | strptime("%Y-%m-%dT%H:%M:%S%z")
That'll only work with a positive timezone offset. An improved version that supports all offsets would be:
sub("(?<time>T[0-9:]+)(\\.\\d+)?(?<tz>Z|[+\\-]\\d{2}:?(\\d\\d)?)$"; .time + .tz) | strptime("%Y-%m-%dT%H:%M:%S%z")
It's a lot uglier, though.
Most helpful comment
Thanks for the workaround! This helps parsing Bunyan log records. I use a slightly altered regex to make sure it's a literal dot:
| sub("\\.[0-9]+Z$"; "Z") | fromdate