clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
mikejcusack 2021-03-05T00:20:27.202200Z

I'm referring to the use of macros like defstyled. I'm looking for something that will fit in nicely with the hiccup in Reagent.

2021-03-05T03:57:55.202400Z

It works really well with reagent: https://dvingo.github.io/cljs-emotion/#!/dv.cljs_emotion.reagent_cards see the last card on that page for an example that doesn't use defstyled

zendevil 2021-03-05T08:30:28.203900Z

I have a ISO timestamp string like so 2021-03-20T07:00:58.000Z

zendevil 2021-03-05T08:30:51.204500Z

What’s the most convenient and least error prone way to convert it into a date and a time according to a specific timezone?

zendevil 2021-03-05T08:31:38.204900Z

in a format like so: March 3, 2021 6 pm

zendevil 2021-03-05T10:11:01.207300Z

@henryw374 the link has the following but I don’t know how to convert it into cljs:

new Intl.DateTimeFormat().format(date)

zendevil 2021-03-05T10:11:20.207500Z

I tried this:

(.format (.DateTimeFormat (js/Intl.) "en-US") date)

zendevil 2021-03-05T10:11:34.208Z

but it’s giving Intl is not a constructor

2021-03-05T10:17:13.208300Z

(-> (js/Intl.DateTimeFormat. "en-AU" #js{:weekday "long"})
    (.format (js/Date.)))

Cj Pangilinan 2021-03-05T10:22:44.208700Z

cljs.user=> (.format (js/Intl.DateTimeFormat. "en-US")) "3/5/2021" cljs.user=> (-> (js/Intl.DateTimeFormat. "en-US") (.format (js/Date.))) "3/5/2021" cljs.user=>

2021-03-05T10:30:27.208900Z

if you're not at a repl already... it's a great way to work out interop syntax ... and do everything else 😉 online one http://app.klipse.tech/

cassiel 2021-03-05T10:56:30.210400Z

As an aside, I notice that “en-GB” in the above still gives me 3/5/2021, not 5/3/2021 which I’d expect. The plain Javascript looks good: > new Intl.DateTimeFormat('en-US').format(new Date()) '3/5/2021' > new Intl.DateTimeFormat('en-GB').format(new Date()) '05/03/2021'

2021-03-05T10:58:38.211100Z

(-> (js/Intl.DateTimeFormat. "en-GB")
    (.format (js/Date.)))
=> "05/03/2021"

raspasov 2021-03-05T11:00:47.212500Z

I believe the dot after DateTimeFormat is optional (but not after (js/Date.)

2021-03-05T11:03:34.212900Z

the . invokes it with newhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new, . not sure if that makes a diff in the case of this fn but the docs all show it being invoked with new so I'd stick with that

raspasov 2021-03-05T11:04:21.213400Z

Hm, yes. Good point.

2021-03-05T11:07:05.215200Z

btw @ps if you're doing much work with dates, including formatting, I would recommend https://github.com/juxt/tick (which I maintain). atm it's quite a lot of code though, so not everyone's cup of tea . see https://github.com/juxt/tick/blob/master/docs/cljs.adoc#optional-timezone--locale-data-for-reducing-build-size

👆 1
cassiel 2021-03-05T11:12:23.215600Z

After I posted, I started to wonder whether it was because for the CLJS I used a bespoke Node that’s bundled with another application (where for the plain JS test it was the standard Node). I’m going to guess that’s the issue and will investigate.

raspasov 2021-03-05T11:12:39.215800Z

For me the biggest stumbling block was dealing with the extra dependencies from ClojureScript (apart from the recent issue I reported I actually tried using tick a few months ago but gave up at the time because I couldn’t make it work in ClojureScript, and for me the Clojure + ClojureScript code re-use is one of the biggest wins of any library that is heavily used across both languages)

raspasov 2021-03-05T11:13:36.216Z

Do you think there’s a way to bundle the extra dependencies as part of deps.edn somehow? Perhaps that’s similar to how ClojureScript bundles the google-closure compiler (if I’m not mistaken) : https://mvnrepository.com/artifact/org.clojure/google-closure-library

2021-03-05T11:16:23.216200Z

it does include those extra dependencies as foreign libs already. so you don't need to bring in the npm deps. but since you are using npm anyway, I'd expect you'd prefer to get them via that route

raspasov 2021-03-05T11:16:54.216400Z

Oh it does? So the npm/yarn step is not necessary?

2021-03-05T11:17:45.216600Z

no, not if the only thing coming from npm was tick deps.

2021-03-05T11:18:07.216800Z

btw shadow would ignore the foreign-libs and do the npm step for you

raspasov 2021-03-05T11:18:31.217Z

(not using shadow)

raspasov 2021-03-05T11:19:01.217200Z

I see that they are included under Dependencies, cool https://clojars.org/tick

2021-03-05T11:19:14.217600Z

but e.g. if you use reagent as well, then you would already do that npm step, and that would pull in tick npm deps as well

2021-03-05T11:20:03.217800Z

in another world, clojurescript deps might be less complicated 🙂

raspasov 2021-03-05T11:20:08.218Z

Hmm… ok (not using reagent)

raspasov 2021-03-05T11:20:50.218200Z

So you’re saying that any use of yarn/npm would pull the juxt/tick dependencies into package.json ?

raspasov 2021-03-05T11:21:52.218400Z

Or just the use through ClojureScript tools/methods like :

clj -m cljs.main --deps-cmd "yarn" --install-deps

2021-03-05T11:22:15.218600Z

yes, just through that. npm on it's own would not

raspasov 2021-03-05T11:22:20.218800Z

Right… ok.

raspasov 2021-03-05T11:23:02.219Z

I generally don’t use any of the clojurescript means, just use: yarn add yarn install etc directly

raspasov 2021-03-05T11:23:17.219200Z

So you’re saying that if I remove all juxt/tick dependencies from package.json, the library should still work (in theory)

2021-03-05T11:23:19.219400Z

and for non-shadow build, if you do use --`install-deps` , then you need to exclude the foreign-libs, otherwise you'll end up with 2 lots of them in your build, which is definitely not small

raspasov 2021-03-05T11:24:13.219600Z

Ah, good point… so why wouldn’t I just stick with the foreign-libs? (for my case, given that I avoid most other ClojureScript+npm/yarn tooling combos)

2021-03-05T11:24:52.220Z

in your case foreign libs sounds fine

raspasov 2021-03-05T11:25:27.220200Z

Cool, I might give it a try 🙂 Thank you for the input! That was very helpful.

2021-03-05T11:25:46.220400Z

:thumbsup:

cassiel 2021-03-05T11:27:29.220600Z

Yup, seems to be the case. Sorry for the noise.

2021-03-05T11:29:41.220900Z

👍

raspasov 2021-03-05T11:49:06.221100Z

Actually, now I recall trying the foreign-libs route some months ago. Is the foreign-libs route expected to work with :advanced ? (I think that was the stumbling block I hit back then)

2021-03-05T11:50:31.221400Z

Yes that works

2021-03-05T11:51:34.221600Z

The tests are done with advanced. And all my work builds use advanced with foreign libs

raspasov 2021-03-05T11:52:11.221800Z

Great! Awesome. Will give it a shot later.

zendevil 2021-03-05T15:05:35.223900Z

I have the following where iso is the iso string coming from a database.

(defn get-local-date [iso]
  (js/console.log "iso is " iso " " (= iso ""))
  (if (and iso (not= iso ""))
    (let [date (js/Date. iso)]
      (js/console.log "date is!!! " date)
      (->
       (js/Intl.DateTimeFormat "en-US"
                               #js {:dateStyle "full" :timeStyle "long"})
       (.format date)))
    ""))
when I print
(get-local-date iso-string)
I’m getting the following:
3/20/2021
Whereas after putting #js {:dateStyle “full” :timeStyle “long”}, I expect a longer date like “March 20, 2021". What am I doing wrong?

thheller 2021-03-05T15:10:02.224300Z

you are missing a .. js/Intl.DateTimeFormat. not js/Intl.DateTimeFormat. its a constructor called with new in JS.