jqlang / jq

Command-line JSON processor
https://jqlang.github.io/jq/
Other
30.23k stars 1.57k forks source link

strptime month does not match input #3138

Closed chuckn246 closed 3 months ago

chuckn246 commented 3 months ago

Describe the bug When using strptime, the month is displayed as -1 of input while all other fields match the input values.

The potential bug is is displayed in the example as well: https://jqlang.github.io/jq/manual/#dates

To Reproduce

$ echo '{ "date": "2024-01-05T23:51:47Z" }' | jq '.date |= strptime("%Y-%m-%dT%H:%M:%SZ")'
{
  "date": [
    2024,
    0, # <---- should this be 1?
    5,
    23,
    51,
    47,
    5,
    4
  ]
}

$ echo '{ "date": "2024-06-08T16:34:21Z" }' | jq '.date |= strptime("%Y-%m-%dT%H:%M:%SZ")'
{
  "date": [
    2024,
    5, # <---- should this be 6?
    8,
    16,
    34,
    21,
    6,
    159
  ]
}

Expected behavior Expect the month digit in the array to match the month from the input.

Environment: System one:

$ uname -a
Darwin hostname 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64

$ jq --version
jq-1.7.1

System two:

$ uname -a
Linux hostname 5.10.0-29-amd64 #1 SMP Debian 5.10.216-1 (2024-05-03) x86_64 GNU/Linux

$ jq --version
jq-1.6

Additional context N/A

pkoppstein commented 3 months ago

For a relevant reference to the "tm" struct see e.g. https://cplusplus.com/reference/ctime/tm/

... the point being that tm_mon is an offset, with January corresponding to 0.

chuckn246 commented 3 months ago

Gotcha, thanks!

I was caught off guard since other values such as day of month doesn't start at zero.

I'll go ahead and close this then :)