Your favorite Clojurescript time solution?

clojurescript

#1

In the past I’ve not done a ton with times, but when I did in CLJS I used cljs-time. At the moment it’s still the only thing I see out there, but the fact that it is trying to imitate clj-time when java-time is better for the back-end makes me a little uncomfortable. What are some recommendations for time handling in cljs?


#2

I use dayjs in my own projects(a tiny replacement for moment.js). There is also Luxon when I need some advanced features. They are npm modules, so, interops…


#3

goog.time (https://google.github.io/closure-library/api/goog.date.html) is a nice CLJS solution, if it’s able to meet your need, because it’s already included in the Closure library.


#4

There’s this https://github.com/gfZeng/time.clj/
Wraps navite javascript datetime stuff.
I’ve only used it a tiny bit tho.


#5

I was wondering about the closure solution. Thanks!


#6

Does anyone have practical comparisons of using one solution vs. another? For example, “cheapest” (included with clojurescript) would be the closure solution. What do moment, luxon, or dayjs facilitate more readily (besides, as with all things closure, better documentation)?


#7

I don’t have a comparison but I used moment, dayjs, luxon. Here’s my impressions:

  • Moment.js - moment is powerful. It supports parsing/formatting dates in various formats and languages. You also got APIs to manipulate dates. Moment is designed with OOP APIs so it looks very nice in JavaScript.
  • date-fns - we want functional programming! So we provided functions to offer those features.
  • Luxon - I(that author @icambron) maintained moment.js and I think we can design a better library by: making dates immutable, better time zone, better API names, etc.
  • Dayjs - we want a light-weight and immutable version of moment.js while we don’t want to learn a new library. Let’s just do it with moment.js APIs.

#8

FWIW, I use clj-time on the server side and moment.js on the client-side, with a bunch of utility functions on top. I’m not perfectly happy with either, and I think there is still place for a small cljc library with a nicer interface.


#9

Glad you asked @Webdev_Tory ;-), because there is now a fully cross-platform Clojure(Script) date/time library, ‘tick’: https://github.com/juxt/tick. The api sits atop java.time on the jvm and a js implementation of java.time (jsr310).

We are building up to an announce shortly and I will be speaking about this at Clojure/North in April.

Linked from the readme are the docs, and I’ll point out there is a section specifically about extra considerations wrt Tick and Clojurescript https://github.com/juxt/tick/blob/master/docs/cljs.adoc

Happy to field any questions here.


#10

I am very excited to look in to tick!