Liking cljdoc? Tell your friends :D

Clojurescript

There are extra considerations when using tick with Clojurescript

Shadow-CLJS

TL;DR to use tick on shadow, follow this demo

Tick uses an npm lib, js-joda which is packaged in cljsjs. Shadow ignores the :foreign-libs directive in the deps.cljs dependency file of that lib, so requires a shim to create the namespace that would normally come from the foreign-lib directive.

In future, tick could instead require consumers to rely on :npm-deps directive in deps.cljs.

Dropping to java.time

Tick doesn’t contain equivalents of every method in java.time (there are ~2.5k in total), but that’s ok because you can use interop syntax. However, Clojurescript does not support Clojure’s static method call syntax. For example

(java.time.Period/parse "P1D")

Is valid Clojure, but not valid Clojurescript. However, using the 'dot' syntax, it is possible to write this so that it works in both Clojure and Clojurescript by using the dot special form:

(. java.time.Period parse "P1D")

Similarly for static property access, the normal Clojure Foo/bar doesn’t work in cljs. Again the solution is to use the dot special form:

(. Foo -bar)

Timezones

If you want to work with timezones, something like this, for example:

 (tick/zone "Europe/London")

add the following require:

[tick.timezone]

Formatting

If you want to create custom formatters from patterns, such as "dd MMM yyyy", add this require:

[tick.locale-en-us]

Why are the extra requires needed?

It is done to allow a smaller payload, when the extra libraries are not being used. Minified, gzipped js-joda (what gets pulled in if you use anything of tick) is around 43k.

Timezone is an extra 26k, and Locale (just en-US) is an extra 45k

Tick uses the js-joda library, which aims to replicate the three-ten-backport project. JS-Joda is broken down into a core project (what tick depends on) and additional timezone and locale projects.

The js-joda timezone dependency contains the timezone database, containing mappings between zone names, their offsets from UTC, and daylight savings(DST) data.

Locale data is needed for custom date formatters which need particular symbols, such as M for month. Due to the size and complexity of using the js-joda-locale, the authors of js-joda-locale have created prebuilt locale packages, for specific locales. en-US is one which is currently packaged for cljs and can be used as suggested above.

OffsetTime and OffsetDateTime

OffsetTime is currently missing from JS-Joda (see JS-Joda issue 240). For now, tick uses LocalTime as the implementation which is not ideal.

OffsetDateTime is also missing but ZonedDateTime has the same functionality so this shouldn’t be a problem.

Can you improve this documentation? These fine people already did:
Henry Widd & Malcolm Sparks
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close