tonsky / tongue

Do-it-yourself i18n library for Clojure/Script
Eclipse Public License 1.0
307 stars 19 forks source link

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

Open ychenz opened 2 years ago

ychenz commented 2 years ago

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 commented 2 years ago

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