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

add locale support for unparse using a formatter #77

Closed
wants to merge 1 commit into from

Conversation

CarlosSam
Copy link

I developed support for localized formatter using the with-locale function.


LocalizedFormatter
(unparse [{:keys [format-str formatters date-time-symbols] :as fmt} dt]
(with-redefs [i/months (.-MONTHS date-time-symbols)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way you can think of to do this without using re-binding vars?
I'm not keen on adding code containing with-redefs to library code.

@@ -233,7 +255,7 @@
:let [d (try (parse-local-date f s) (catch js/Error _ nil))]
:when d] d))))

(defn unparse
(defn do-unparse
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep this function as part of the API, and perhaps defer to the protocol implementation for say -unparse. That's how clojurescript core does this kind of thing... it's a bit more flexible that way.

lfmt-month (with-locale fmt-month goog.i18n.DateTimeSymbols_fr)]
(is (= "quinta-feira, 11 de março de 2010" (unparse lfmt (local-date 2010 3 11))))
(is (= "lundi 11 février 2013" (unparse lfmt-month (local-date 2013 2 11))))))

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests! Awesome :)

@andrewmcveigh
Copy link
Owner

andrewmcveigh commented Nov 3, 2016

Hey,

Thanks very much for this. I've a couple comments above. Mainly about the use of with-redefs. Personally I don't think using with-redefs (or really rebinding vars in general) is suitable for library code. It could lead to really unexpected bugs for users. Is there a way to do this with a more functional approach?

@andrewmcveigh
Copy link
Owner

andrewmcveigh commented Feb 28, 2017

See #85 for a fuller implementation.

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

Successfully merging this pull request may close these issues.

2 participants