jq icon indicating copy to clipboard operation
jq copied to clipboard

`fromdateiso8601` doesn't support the "decimal fraction" component in time values.

Open slippycheeze opened this issue 3 years ago • 7 comments

Describe the bug The ISO8601 time format supports a decimal fraction attached to the smallest component present; this is passably common for seconds to represent micro- or nano-seconds. Technically this is also applicable to the minute and hour components, though I have never seen that used in the wild.

fromdateiso8601 doesn't handle fractional seconds, which is an annoyance since I have several JSON applications that emit them, and where I'd like to do some date comparisons.

To Reproduce

] jq -nr '"2020-12-11T01:00:52.605001Z" | fromdateiso8601'
jq: error (at <unknown>): date "2020-12-11T01:00:52.605001Z" does not match format "%Y-%m-%dT%H:%M:%SZ"

Expected behavior jq(1) would parse fractional seconds; ideally, it would also carry and emit them, but just ignoring the fraction would be sufficient for my needs.

Environment (please complete the following information):

  • macOS 10.15.7 x64
  • jq-1.6

Additional context This is definitely an extension on the basic POSIX time functions, so perhaps isn't interesting to jq. I'd hope it was, since they are fairly commonly used, but I understand if this is bounced as "not interested".

slippycheeze avatar Dec 10 '20 17:12 slippycheeze

Having this issue also (MacOS 11.2.3, jq 1.6). It is rejecting my fractions.

ecarlseen avatar Apr 09 '21 00:04 ecarlseen

Is there any solution to this yet? I have a date like "1649333768.581" that I need to compare.

mbierman avatar Apr 07 '22 20:04 mbierman

Only workaround I found for now is to truncate the date and add the Z.

So the example of the initial issue description would be:

jq -nr '"2020-12-11T01:00:52.605001Z" | .[0:19] +"Z" | fromdateiso8601'

Not the most elegant, but it works ¯\_(ツ)_/¯

yaningo avatar Jan 21 '23 23:01 yaningo

FWIW https://github.com/01mf02/jaq handles this correctly.

jcmorrow avatar Nov 29 '23 20:11 jcmorrow