Liking cljdoc? Tell your friends :D

Clojurescript

There are extra considerations when using tick with Clojurescript

Dropping to java.time

Tick doesn’t contain equivalents of every method in java.time (which in total has about ~2.5k), 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:

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

Property access is another problem, because Clojurescript properties are prefixed with a '-'. For example to access property bar on foo:

(.-bar foo)

To get around this problem, there is a macro tick.interop/static-prop

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?Edit on GitHub

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

× close