itchyny / gojq

Pure Go implementation of jq
MIT License
3.3k stars 119 forks source link

Week number is not taken into account during date creation in `strptime` #254

Closed traut closed 5 months ago

traut commented 5 months ago

It looks like gojq ignores the week number during strptime while JQ uses it for the output date:

$ jq -n '"2024, 20" | strptime("%Y, %W") | strftime("%Y-%m-%d")'
"2024-05-13"

$ gojq -n '"2024, 20" | strptime("%Y, %W") | strftime("%Y-%m-%d")'
"2024-01-01"

$ jq --version
jq-1.7

$ gojq --version
gojq 0.12.15 (rev: HEAD/go1.21.4)
traut commented 5 months ago

moreover, it seems even incorrect week numbers are not caught:

$ jq -n '"2024, 99" | strptime("%Y, %W") | strftime("%Y-%m-%d")'
jq: error (at <unknown>): date "2024, 99" does not match format "%Y, %W"

$ gojq -n '"2024, 99" | strptime("%Y, %W") | strftime("%Y-%m-%d")'
"2024-01-01"
traut commented 5 months ago

ah, this (from timefmt lib) explains the behavior -- the value for %W is parsed out but discarded 😞

itchyny commented 5 months ago

I have implemented parsing support for week numbers locally, will soon push to the repository.

itchyny commented 5 months ago

I have created a branch building with the latest timefmt-go with week number support, you can download the artifacts from here.

itchyny commented 5 months ago

Resolved by 1324e6e320cff2b2eb9c778cfa1f960245ad41ad.