clojure icon indicating copy to clipboard operation
clojure copied to clipboard

Java Time API with Clojure

Open practicalli-johnny opened this issue 3 years ago • 0 comments

Projects

  • juxt/tick - time as a value (uses cljc.java-time and time-literals projects under the covers)
  • https://github.com/henryw374/cljc.java-time - library for Clojure and ClojureScript projects, with kebab-case named vars and predicate functions
  • time-literals
  • clojure.java-time - a simple wrapper around the Java Time API

Deprecated projects

  • clj-time/clj-time
  • joda-time (used as the basis for Java TIme API) - deprecated since Java 8 introduced the Java Time API

References

  • https://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html

Practicalli pages to update

https://practical.li/clojure/reference/clojure-syntax/more-java-fun.html

TODO: Add Date Time section to Reference > Standard Library section

  • use juxt/tick as the defacto library for both Clojure and ClojureScript projects (tick uses cljc.java-time under the hood)
  • add any meaningful comparisions to using cljc.java-time or juxt/tick
  • examples of using Clojure.java-time and Java Time API
    • using Java Time API directly removed the need for a library dependency
  • summary of why to choose one of the mentioned projects

clojure.java-time example

Add clojure.java-time to project deps.edn file

{:paths ["src"]
 :deps {org.clojure/clojure {:mvn/version "1.10.1"}
            clojure.java-time {:mvn/version "0.3.2"}}}

Require java-time namespace. call local-date-time to get the date and time when the function was called

(ns practicalli.what-time-is-it
  (:require [java-time :as time]))

(defn -main []
  (println "The time according to Clojure java-time is:"
           (time/local-date-time)))

practicalli-johnny avatar Mar 20 '22 21:03 practicalli-johnny