(require '[tick.core :as t])
;; Get the current time
(t/now)
A Clojure(Script) library for dealing with time. Intended as a replacement for clj-time.
Based on Java 8 time (on the JVM) and js-joda (on JavaScript runtimes). We are considering an implementation based on Temporal, via Tempo when it is available.
(require '[tick.core :as t])
;; Get the current time
(t/now)
See Henry Widd’s talk at Clojure/North 2019 for some background
In both Clojure and Clojurescript versions, tick is just calling through to java.time methods. Understanding the main entities of java.time is necessary to use tick. For example, one should know that there are 2 separate ways to measure amounts of time, 3 ways to represent a point on the timeline and so on.
Instants are not 'calendar-aware' - they just contain millis/nanos field representing an offset from the Unix epoch. This means Instants have no method to get their year or month for example, because to do so would require a calendar (e.g. the Gregorian calendar).
Tick provides some help with this when accessing properties of an Instant though. For example
(t/year (t/now))
works. To make that possible, tick first converts the Instant into a ZonedDateTime
(which does have a calendar). Take note however that the zone of the ZonedDateTime will be the
browser’s or jvm’s timezone. To be explicit about the zone required do this:
(-> (t/now)
(t/in "UTC")
t/year)
The other cases where calendar-awareness might come up is when formatting Instants to string or when shifting them by e.g. years/months, so Tick shows explanatory error messages in that case.
As with java.time, any functions working with amounts of time (ie Durations or Periods),
will have names which are in the plural. Functions that
work with dates and times are singular. Knowing that, e.g. t/second
vs t/seconds
makes sense.
tick.core - stable
tick.alpha.interval - Alpha: Ready to use with the caveat that the API might still undergo minor changes.
Get the latest from Clojars and
add to your project.clj
, build.boot
or deps.edn
.
To use this from Clojurescript, you must have at least version 1.11.51. If using shadow-cljs, it must be at least version 2.19.3
For Clojurescript users of Tick, see docs/cljs.adoc, for some discussion around Clojurescript build size.
Here is a one-liner to drop into a node repl with tick:
clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE" } tick/tick {:mvn/version "RELEASE"} }}' -m cljs.main -re node --repl
Build the html
make
Build the CLJS and start a figwheel repl+server
make dev-docs-cljs
Navigate to localhost:9500 in your browser
make release-docs-cljs
clj -Atest-clj:test-cljs
To start testing clojurescript, follow instructions in the cljs
ns.
To start testing clojure, follow instructions in the the repl
ns.
See the .github dir to see instructions for CLI testing
create a git tag.
make install
(this installs in ~/.m2 - check that things look ok)
make deploy
- you need to have set up clojars credentials as per https://github.com/applied-science/deps-library
git push origin new-tag-name
In particular, special credit to Eric Evans for discovering Allen’s interval algebra and pointing out its potential usefulness, demonstrating a working implementation of Allen’s ideas in his Clojure library.
Thanks also to my esteemed colleagues Patrik Kårlin for his redesign of the interval constructor function, and Henry Widd for porting to cljc.
The MIT License (MIT)
Copyright © 2016-2021 JUXT LTD.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Can you improve this documentation? These fine people already did:
Henry Widd, Malcolm Sparks, Andrea Crotti, Martin Klepsch, Arne Brasseur, Caro, Xavi Caballé, Alex Davis & Oliver GeorgeEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close