hapi-server / uri-templates

Repository of tools for URI templates
Apache License 2.0
2 stars 0 forks source link

iso8601 parser to support week-of-year #10

Closed jbfaden closed 2 years ago

jbfaden commented 2 years ago

The iso8601 parser hasn't ever supported week-of-year and I needed it for some application. I just realized I put the code in but the change was never documented in a ticket.

So TimeUtil.java the following now parses:

Code equivalent time
2022-W13/P7D 2022-03-28T00:00Z/2022-04-04T00:00Z
2022-W01/P7D 2022-01-03T00:00Z/2022-01-10T00:00Z
2021-W52/P7D 2021-12-27T00:00Z/2022-01-03T00:00Z

See https://github.com/autoplot/dev/blob/master/demos/2022/20220312/demotimeWeek.jy

jbfaden commented 2 years ago

The date command supports week-of-year, so I suggest:

date +%Y-W%W-%w
2022-W10-6

some care is needed because there is also %V:

spot8> date -d 2022-01-01 +%Y-W%V-%w
2022-W52-6
spot8> date -d 2022-01-01 +%Y-W%W-%w
2022-W00-6
spot8> date -d 2021-12-31 +%Y-W%W-%w
2021-W52-5

The ISO8601 standard has no week 0.