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

No way to default date? #115

Open
mtravers opened this issue Nov 14, 2024 · 1 comment
Open

No way to default date? #115

mtravers opened this issue Nov 14, 2024 · 1 comment

Comments

@mtravers
Copy link

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

@mtravers
Copy link
Author

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))))))

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