• Stars
    star
    581
  • Rank 74,051 (Top 2 %)
  • Language
    Clojure
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Time as a value.

clojars tests build bb compatible

tick

A Clojure(Script) & babashka 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). Javascript’s modern date-time API Temporal is a consideration as an alternative foundation for tick in future. See the Tempo library if interested.

Status

  • tick.core - stable

  • tick.alpha.interval - Alpha: Ready to use with the caveat that the API might still undergo minor changes. Note also that this part of tick is not being actively maintained at the moment (other than to keep existing tests passing). There are currently around 10 open tickets relating to intervals which no one is looking at. It may be maintained again in the future of course.

Should you use Tick for date-time work?

  • If you are just working on the JVM and are comfortable with the java.time API then raw interop will work just fine.

  • If you are working in a Javascript environment then seriously consider using cljc.java-time: Its build size will not adversely affect your users (unless in a highly constrained context such as a microcontroller). The reason is the native Date API is flawed

  • If you meet any of the following criteria, use cljc.java-time:

    • are creating cross-platform date-time logic

    • are not proficient in java.time and would like improved error messages

    • would rather not maintain type hints in your code

  • If you meet the criteria to use cljc.java-time but would like a more terse API and the benefits of e.g. (t/with-clock …​) but will not miss having every date-time recipe one google search away, then tick might be a good choice. Tick uses cljc.java-time so you can always drop to that if Tick is missing something you need.

  • Similar in aiming for a terse API, but jvm-only is clojure.java-time.

Usage

(require '[tick.core :as t])

;; Get the current time
(t/instant)

Top tips

java.time

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 (Period and Duration), 3 ways to represent a point on the timeline (Instant, ZonedDateTime & OffsetDateTime) and so on.

Instants

Instants are not 'calendar-aware' - they just contain millis+nanos fields 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).

However, the following does work in Tick: (t/year (t/instant)). 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/instant)
    (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.

Singular vs Plural ?

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.

Install

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

If using cljsjs, add js-joda and js-joda-locale-en-us and js-joda-timezone to your dependencies as well.

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"} henryw374/js-joda {:mvn/version "RELEASE"} }}' -m cljs.main  -re node  --repl

Here is how to get to a babashka (v 1.2.174+) repl with tick:

export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {tick/tick {:mvn/version "0.6.0"}}}')

bb

Development

Develop The Documentation Site

Build the html

make

make dev-docs-cljs to build the js for the site needs fixing.

=== Build a production version of the Documentation Site

The following is not working currently:

make release-docs-cljs

=== Develop Tick

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

=== Release

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`

== Acknowledgements

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
link:https://github.com/domainlanguage/time-count[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.

== References

* https://github.com/dm3/clojure.java-time
* https://clojuresync.com/emily-ashley/
* https://github.com/aphyr/tea-time
* https://github.com/sunng87/rigui

== Copyright & License

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.

More Repositories

1

bidi

Bidirectional URI routing
Clojure
984
star
2

yada

A powerful Clojure web library, full HTTP, full async - see https://juxt.pro/yada/index.html
HTML
731
star
3

aero

A small library for explicit, intentful configuration.
Clojure
721
star
4

edge

A Clojure application foundation from JUXT
Clojure
502
star
5

joplin

Flexible datastore migration and seeding for Clojure projects
Clojure
313
star
6

juxt-accounting

Double-entry accounting software written in Clojure with Datomic.
Clojure
280
star
7

pack.alpha

Package clojure projects
Java
259
star
8

mach

A remake of make (in ClojureScript)
Clojure
246
star
9

jig

Jig is an application harness providing a beautifully interactive development experience for Clojure projects.
Clojure
230
star
10

clip

Light structure and support for dependency injection
Clojure
224
star
11

iota

Infix operators for test assertions
Clojure
149
star
12

site

A web and API server, powered by xtdb.com
Clojure
136
star
13

modular

JavaScript
128
star
14

apex

A compendium of Clojure libraries for implementing web backends.
Clojure
124
star
15

bolt

An integrated security system for applications built on component
Clojure
123
star
16

jinx

jinx is not xml-schema (it's json-schema!)
Clojure
97
star
17

pull

Trees from tables
Clojure
96
star
18

roll

AWS Blue/Green deployment using Clojure flavoured devops
Clojure
75
star
19

reap

A Clojure library for decoding and encoding strings used by web protocols.
Clojure
68
star
20

dirwatch

A Clojure directory watcher, wrapping the JDK 7 java.nio.file.WatchService.
Clojure
67
star
21

skip

Skippy McSkipface - A general Clojure dependency tracker
Clojure
34
star
22

snap

Snapshot testing for Clojure and Clojurescript
Clojure
29
star
23

pack-datomic

Datomic Packer and Terraform setup
HCL
26
star
24

qcon2014

JavaScript
26
star
25

stoic

Marrying the Component Lifecycle pattern with distributed config.
Clojure
20
star
26

spin

Unbundling the web application-tier
Clojure
20
star
27

pick

A Clojure library for HTTP server-driven content negotiation.
Clojure
18
star
28

prop

Clojure
17
star
29

rest

A guide to coding a REST service
CSS
16
star
30

grab

A Clojure library for parsing and executing GraphQL queries.
Clojure
16
star
31

chatserver

Clojure
13
star
32

shop

The JUXT Shop - a sample application built on Crux
Clojure
11
star
33

dotfiles

Recommended dotfiles used by JUXT
Emacs Lisp
9
star
34

fuzz

Example ClojureScript Project that happens to wrap Slack
Clojure
9
star
35

ramp

Shell
8
star
36

card

Not sure what this is. A kind-of Zettelkasten?
TypeScript
8
star
37

chatclient

Clojure
8
star
38

hire

A technical interview test for potential employees
Clojure
7
star
39

rock

Hardened AMIs for Clojure deployments (Arch Linux)
Shell
7
star
40

clip-example

Example of using Clip
Clojure
7
star
41

datomic-extras

Clojure
7
star
42

lein-dockerstalk

Clojure
7
star
43

docker

Docker files
Makefile
7
star
44

draw

A DSL for SVG diagrams
Clojure
6
star
45

trag

Graph transduction
Clojure
5
star
46

radar

JUXT Clojure Technology Radar
Clojure
5
star
47

vext

Clojure
4
star
48

pack-ek

HCL
4
star
49

adoc

A Clojure wrapper for asciidoctorj
Clojure
4
star
50

msf

Volunteer work for MSF
Clojure
4
star
51

astro-website

Source for the main JUXT website
JavaScript
3
star
52

azondi

MQTT goes reactive
CSS
3
star
53

pack-riemann

HCL
3
star
54

http

3
star
55

yada.cookbook

A cookbook of yada recipes
3
star
56

component-utils

Clojure
2
star
57

blip

Small library for fetching/injecting graphql definitions
Clojure
2
star
58

flow

Clojure
2
star
59

ping

Clojure
2
star
60

modular.co-dependency

Co-dependency support for com.stuartsierra.component
Clojure
2
star
61

lein-deploy-tar

A Leiningen plugin to upload tars to a Maven repository.
Clojure
2
star
62

aleph-issue

Testing aleph
Clojure
1
star
63

mksmarthack

A Clojure data hack on MK:Smart
Clojure
1
star
64

eventing-examples

Clojure
1
star
65

training-exercises-webapp

Training exercises
Clojure
1
star
66

example-code

Example code for a recent client course
Clojure
1
star
67

home-apps

Monorepo for SPAs that use home.juxt.site as a backend
TypeScript
1
star
68

sail

Clojure
1
star
69

clojars-mirrors

Re-releasing Clojars libraries onto Maven Central
Clojure
1
star
70

XT20.conf

Public materials for XT20
1
star
71

asciidoctor-stylesheet-factory

CSS
1
star