andrewmcveigh / cljs-time

A clj-time inspired date library for clojurescript.
342 stars 57 forks source link

It seems that week number of a year does not satisfy ISO8601 #98

Closed HaskellZhangSong closed 6 years ago

HaskellZhangSong commented 7 years ago
    =>(require '[cljs-time.format :as f])
    =>(require '[cljs-time.core :as t])
    =>(def date (t/date-time 2017))
    =>(def format (f/formatter "xxxx'W'wwe'T'HHmmssZ"))
    =>(f/unparse format date)
    "2017W010T000000Z"

according to https://en.wikipedia.org/wiki/ISO_8601#Week_dates

the week day of 20170101 should belong to the last week of previous year. so the result should actually be 2016W520T000000Z.

And the format does not seem to accept single 'w' character for week number of a year to remove prefix 0. Although this is not in ISO 8601, clj-time and other date-related package of other languages support this.

shen-tian commented 6 years ago

Looks like this is (semi) fixed now? (Looking at 0.5.0).

=> (def date (time/date-time 2017))
=> (def format (time-format/formatter "xxxx'W'ww"))
=> (time-format/unparse format date)
"2016W52"

Running it on the full format string "xxxx'W'wwe'T'HHmmssZ" generates an exception starting with #object[Error Error: No matching clause: e] etc. But this might be related to #116 ?