Hi all I have a question about parsing date with Juxt tick library
t/parse-date "01-Jan-84" (t/formatter "dd-MMM-yy" )) the output is 2084-01-01 instead of 1984-01-01 is there any to prevent it or I have to handle it myself, thank you
you need to handle reduced precision: on jvm:
(t/parse-date "01-Jan-84" (-> (java.time.format.DateTimeFormatterBuilder.) (.appendPattern "dd-MMM-") (.appendValueReduced java.time.temporal.ChronoField/YEAR 2 2 1900) (.toFormatter)))
you should be able to build the formatter with cljc.java-time.format.date-time-formatter-builder for a cross platform versionyou may want to adjust the base year, pick the earliest year expected so that it also handles years in the early 2000 (e.g. 1980 will parse 92 as 1992 and 75 as 2075)
Ok thanks I’ll give that a try
I also found out Java can’t handle Sep, it has to be Sept for MMM
it works on my computer with Sep, and Sept doesn't, could be a locale issue ?
Probably, but are you using cljc or tick?
it should be the same for parsing, I tried with tick
if you only handle dates in this particular format it might be easier to build your own parsing method at this point
you may have a copy and paste error I get 2084-01-01 , basically because the data only specifies the last 2 digits of the year, the parser has to guess as to what century the year is in
thanks for getting back, sorry i type it wrong, it was 2084 instead of 2089 let me change that, so I should handling the case myself then?
I am not very familiar with tick, but it seems like you would have to, what to do with underspecified data (yeas missing the century) doesn't seem like a 1 size fits all
i guess this is an edge case and Swift foundation took care of that, I’ll handle it myself then thanks!