clojure.java-time
clojure.java-time copied to clipboard
No way to default date?
I want to parse strings like "November 2024" and default the day of the month to 1. The underlying java classes support this I think (see here) but this isn't brought out into the Clojure API
Hacked a version that does what I want, probably it should be under an option.
(defn ^java.time.format.DateTimeFormatter formatter
([fmt]
(formatter fmt {}))
([fmt {:keys [resolver-style case] :or {case :sensitive}}]
(let [^DateTimeFormatter fmt
(cond (instance? DateTimeFormatter fmt) fmt
(string? fmt) (.. (get-case-formatter case)
(appendPattern fmt)
(parseDefaulting java.time.temporal.ChronoField/DAY_OF_MONTH 1)
toFormatter)
:else (get jf/predefined-formatters (name fmt)))]
(cond-> fmt
resolver-style (.withResolverStyle (get-resolver-style resolver-style))))))