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

[Readme improvement] Misleading README docs about date formatting using ClojureScript #34

Open
ychenz opened this issue Feb 23, 2022 · 1 comment

Comments

@ychenz
Copy link

ychenz commented Feb 23, 2022

Hi team!

I am pretty new to ClojureScript and developing using Shadow-cljs and Reframe. The part of README that explains how to format date using the translate function works fine only when plain strings are passed, but it will throw a compilation error as soon as the plain string is replaced with a variable:

Here is what's mentioned in the README

(translate :en :date-full     #inst "2016-01-01T15:00:00") ;; => "January 1, 2016"
(translate :en :date-short    #inst "2016-01-01T15:00:00") ;; => "1/1/16"
(translate :en :time-military #inst "2016-01-01T15:00:00") ;; => "1500"

Here is the error screenshot:
image

The error is resolved when I replaced #inst <string-var> with (js/Date. <string-var>). I'm just thinking maybe it is better to mention this in the README so it will be easier for new developers to use this library.

Thank you!
Yuchen

@tonsky
Copy link
Owner

tonsky commented Feb 23, 2022

I see what you are talking about, but this is part of Clojure language and has nothing to do with the library. That’s how reader tags work—they are processed roughly at the parsing stage, before any of the variables has a chance to resolved.

Think of #inst " as of fancy quotation mark ", just a little longer and producing Date instead of a String.

See https://clojure.org/reference/reader#_built_in_tagged_literals

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

2 participants