Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing years with 2 digits or leading zeros #146

Open
bgalartza opened this issue May 10, 2022 · 0 comments
Open

Parsing years with 2 digits or leading zeros #146

bgalartza opened this issue May 10, 2022 · 0 comments

Comments

@bgalartza
Copy link

bgalartza commented May 10, 2022

When trying to parse dates that contain years with 2 digits (years <= 99), or leading zeros (ej "0099") ,the library automatically adds the century.

cljs.user> (cljs-time.format/parse (cljs-time.format/formatter "yyyy-MM-DD") "99-12-10")
#object[Object 19991210T000000]
cljs.user> (cljs-time.format/parse (cljs-time.format/formatter "yyyy-MM-DD") "0001-12-10")                                                                                                    
#object[Object 20011210T000000] 
cljs.user> (cljs-time.format/parse "0000-10-15T23:50:58.165Z")                                                                                                                                
#object[Object 20001015T235058

First I thought it might be a bug, but after checking the involved code, it looks like it's the expected behavior. Also, found that regular JS Date objects have a similar behavior.

But I wonder if there is any workaround, configuration parameter, or method to avoid the year inference to actually parse years < 99. As IMHO it's a valid use case.

As reference this is the behaviour of the java-time Clojure library in this aspect:

dev> (java-time/local-date "yyyy-MM-dd" "0001-12-10")                                                                                                                                         
#object[java.time.LocalDate 0x3520f56d "0001-12-10"]

dev> (java-time/local-date "yy-MM-dd" "01-12-10")                                                                                                                                             
#object[java.time.LocalDate 0x6317782c "2001-12-10"]

This issue in the Google Closure library might also be interesting.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant