joda time extensions for hara.time
In project.clj, add to dependencies:
[im.chit/hara.time "2.2.17"]
[im.chit/hara.time.joda "2.2.17"]
Please see the main documentation for hara.time, for the complete API this library adds org.joda.time.DateTime
to the avaliable list of datetime representations supported by the hara.time
framework.
(require '[hara.time :as t]
'[hara.time.joda])
Convert to and from long and map representations via DateTime:
(-> (t/from-long 0 {:type DateTime :timezone "Asia/Kolkata"})
(t/to-map))
;;=> {:type org.joda.time.DateTime,
;; :timezone "Asia/Kolkata", :long 0
;; :year 1970, :month 1, :day 1,
;; :hour 5, :minute 30, :second 0, :millisecond 0}
Using the addition and subtraction interface:
(-> (DateTime. 0)
(t/plus {:weeks 4})
(t/minus {:days 28})
(t/to-long))
;;=> 0
(-> (DateTime. 0)
(t/plus {:years 10})
(t/coerce {:type Date}))
;;=> #inst "1980-01-01T00:00:00.000-00:00"
Having a consistent interface for format and parse:
(t/format (DateTime. 0) "MM dd yyyy")
;;=> "01 01 1970"
(-> (t/parse "00 00 01 01 01 1989 +0000"
"ss mm HH dd MM yyyy Z"
{:type DateTime
:timezone "GMT"})
(t/to-map))
;;=> {:type org.joda.time.DateTime,
;; :timezone "Etc/GMT",
;; :year 1989, :month 1, :day 1,
;; :hour 1, :minute 0, :second 0, :millisecond 0}
Copyright © 2016 Chris Zheng
Distributed under the MIT License