## Cross Platform Date-Time Awesomeness #### by Henry Widd #### @henryw374
```clojure (ns foo.cljc (:require #?(:clj [clj-time.core :as ct] :cljs [cljs-time.core :as ct]))) (ct/before? (ct/today) (ct/today)) ; => true (in cljs) ```
#### Why Cross-Platform Code? ![alt text](/images/cljc.jpg)
![alt text](/images/plumbing-brain.svg)
![alt text](/images/plumbing-brain-cljc.svg)
#?@(...)

Maths: kixi.stats

Strings: cuerdas

Data: frankiesardo/linked

Dates: ____

#### java.time & js-joda date objects ![jsr310 domain](/images/jsr310-domain.svg "jsr310-domain" )
### Cross-Platform java.time ```clojure (ns foo (:require #?(:cljs [java.time :refer [LocalDate]]) ;(1) [time-literals.read-write]) #?(:clj (:import [java.time LocalDate]))) ;(2) (def d (. LocalDate parse "2015-10-21")) ;(3) ;=> #time/date"2015-10-21" ;(4) (= d (. LocalDate now)) ; => false (-> d (.atStartOfDay (. ZoneId systemDefault))) ;(5) ; #time/zoned-date-time"2015-10-21T00:00-04:00[America/New_York]" ```
## A Clojure wrapper for x * Provides? * Avoid Interop Code * Clojurey Version of the API (e.g. data in/out) * Extra features (API, Immutability etc) * Need to know: * Do I need to know x? Is the API tied to x? * Do x's docs, community & Stack overflow translate
## cljc.java-time ```clj (ns my.cljc (:require [cljc.java-time.local-date :as local-date]) ;(1) (def d (local-date/parse "2019-01-01")) ;(2) (local-date/at-start-of-day d) ; => #time/date-time"2020-12-01T00:00" ```
## clojure.java-time * Clojurey-ness * Data API - fields and units * Single namespace * Features * `(with-clock ...)` * Conversions to/from Joda, java.sql.* & other date types

Tick


Authored by Malcolm Sparks @ JUXT

Power Tools for working with Time

How much annual leave has an employee used up?

Inputs:


what periods have they been out of office?

Relevant public holiday calendar

annual leave allowance start/end

## Interval Operations ```clojure (require '[tick.alpha.api :as t]) (def working-days (t/difference ;(1) #:tick{:beginning #time/date "2012-01-01", :end #time/date "2020-01-01"} weekends public-holidays)) ; => (#:tick{:beginning #time/date "2012-01-03" ;(2) ; :end #time/date "2012-01-07"} ; .... ) (def holidays-by-year (-> (t/intersection working-days employee-holidays) (t/group-by t/year))) ;(3) ; => {#time/year"2012" (#:tick{:beginning #time/date "2012-01-03", :end #time/date "2012-01-07"} .... ) ; {#time/year"2013" (#:tick{:beginning #time/date "2013-04-05", :end #time/date "2013-04-13"} .... ) ; ...} ```
## Tick ```clojure (-> (t/time "10am") (t/on "2019-04-20") (t/in "America/Toronto")) ```
### Recap ```clojure [tick] ;(alpha) [cljc.java-time] [cljs.java-time] [cljsjs/js-joda] [time-literals] [cljs.java-time] ```
## For The Future ... * tc39/proposal-temporal & Intl api * specs (and generators, similar to `s/inst-in`) * tick - '1.0' - more docs etc * automated tracking and publishing of discrepancies between java.time and js-joda * incl. methods added to java.time in Java 9 and higher * decide what cljc.java-time should do
## To Wrap up... * I got the cross platform date-time APIs I wanted * big shoutout to the JS-Joda authors & others * Consider defaulting to cljc
## Links @henryw374 * [My Blog](http://widdindustries.com/) * [tick](https://github.com/juxt/tick) * [time-literals](https://github.com/henryw374/time-literals) * [cljc.java-time](https://github.com/henryw374/cljc.java-time)