Liking cljdoc? Tell your friends :D

hara.time


adjustclj

(adjust t rep)
(adjust t rep opts)

adjust fields of a particular time (t/adjust (Date. 0) {:year 2000 :second 10} {:timezone "GMT"}) => #inst "2000-01-01T00:00:10.000-00:00"

adjust fields of a particular time
(t/adjust (Date. 0) {:year 2000 :second 10} {:timezone "GMT"})
=> #inst "2000-01-01T00:00:10.000-00:00"
raw docstring

afterclj

(after t1 t2)
(after t1 t2 & more)

compare dates, returns true if t1 is after t2, etc (t/after 2 (Date. 1) (common/calendar (Date. 0) (TimeZone/getTimeZone "GMT"))) => true

compare dates, returns true if t1 is after t2, etc
(t/after 2
         (Date. 1)
         (common/calendar
          (Date. 0)
          (TimeZone/getTimeZone "GMT")))
=> true
raw docstring

beforeclj

(before t1 t2)
(before t1 t2 & more)

compare dates, returns true if t1 is before t2, etc (t/before 0 (Date. 1) (common/calendar (Date. 2) (TimeZone/getTimeZone "GMT"))) => true

compare dates, returns true if t1 is before t2, etc
(t/before 0
          (Date. 1)
          (common/calendar
           (Date. 2)
           (TimeZone/getTimeZone "GMT")))
=> true
raw docstring

coerceclj

(coerce t {:keys [type timezone] :as opts})

adjust fields of a particular time (t/coerce 0 {:type Date}) => #inst "1970-01-01T00:00:00.000-00:00"

(t/coerce {:type clojure.lang.PersistentHashMap, :timezone "PST", :long 915148800000, :year 1999, :month 1, :day 1, :hour 0, :minute 0 :second 0, :millisecond 0} {:type Date}) => #inst "1999-01-01T08:00:00.000-00:00"

adjust fields of a particular time
(t/coerce 0 {:type Date})
=> #inst "1970-01-01T00:00:00.000-00:00"

(t/coerce {:type clojure.lang.PersistentHashMap,
           :timezone "PST", :long 915148800000,
           :year 1999, :month 1, :day 1, :hour 0, :minute 0 :second 0, :millisecond 0}
          {:type Date})
=> #inst "1999-01-01T08:00:00.000-00:00"
raw docstring

dayclj

(day t)
(day t opts)

accesses the day representated by the instant (t/day 0 {:timezone "GMT"}) => 1

(t/day (Date. 0) {:timezone "EST"}) => 31

accesses the day representated by the instant
(t/day 0 {:timezone "GMT"}) => 1

(t/day (Date. 0) {:timezone "EST"}) => 31
raw docstring

day-of-weekclj

(day-of-week t)
(day-of-week t opts)

accesses the day of week representated by the instant (t/day-of-week 0 {:timezone "GMT"}) => 4

(t/day-of-week (Date. 0) {:timezone "EST"}) => 3

accesses the day of week representated by the instant
(t/day-of-week 0 {:timezone "GMT"}) => 4

(t/day-of-week (Date. 0) {:timezone "EST"}) => 3
raw docstring

default-timezoneclj

(default-timezone)
(default-timezone tz)

accesses the default timezone as a string

(default-timezone) ;; getter => "Asia/Ho_Chi_Minh"

(default-timezone "GMT") ;; setter => "GMT"

accesses the default timezone as a string
       
(default-timezone)  ;; getter
=> "Asia/Ho_Chi_Minh"

(default-timezone "GMT")  ;; setter
=> "GMT"
raw docstring

default-typeclj

(default-type)
(default-type cls)

accesses the default type for datetime

(default-type) ;; getter => clojure.lang.PersistentArrayMap

(default-type Long) ;; setter => java.lang.Long

accesses the default type for datetime

(default-type) ;; getter
=> clojure.lang.PersistentArrayMap

(default-type Long) ;; setter
=> java.lang.Long
raw docstring

duration?clj

(duration? obj)

checks if an object implements the duration protocol (t/duration? 0) => true

(t/duration? {:weeks 1}) => true

checks if an object implements the duration protocol
(t/duration? 0) => true

(t/duration? {:weeks 1})
=> true
raw docstring

earliestclj

(earliest t1 t2 & more)

returns the earliest date out of a range of inputs (t/earliest (Date. 0) (Date. 1000) (Date. 20000)) => #inst "1970-01-01T00:00:00.000-00:00"

returns the earliest date out of a range of inputs
(t/earliest (Date. 0) (Date. 1000) (Date. 20000))
=> #inst "1970-01-01T00:00:00.000-00:00"
raw docstring

epochclj

(epoch)
(epoch opts)

returns the beginning of unix epoch (t/epoch {:type Date}) => #inst "1970-01-01T00:00:00.000-00:00"

returns the beginning of unix epoch
(t/epoch {:type Date})
=> #inst "1970-01-01T00:00:00.000-00:00"
raw docstring

equalclj

(equal t1 t2)
(equal t1 t2 & more)

compares dates, retruns true if all inputs are the same (t/equal 1 (Date. 1) (common/calendar (Date. 1) (TimeZone/getTimeZone "GMT"))) => true

compares dates, retruns true if all inputs are the same
(t/equal 1
         (Date. 1)
         (common/calendar
          (Date. 1)
          (TimeZone/getTimeZone "GMT")))
=> true
raw docstring

formatclj

(format t pattern)
(format t pattern {:keys [cached] :as opts})

converts a date into a string

(f/format (Date. 0) "HH MM dd Z" {:timezone "GMT" :cached true}) => "00 01 01 +0000"

(f/format (common/calendar (Date. 0) (TimeZone/getTimeZone "GMT")) "HH MM dd Z" {}) => "00 01 01 +0000"

(f/format (Timestamp. 0) "HH MM dd Z" {:timezone "PST"}) => "16 12 31 -0800"

(f/format (Date. 0) "HH MM dd Z") => string?

converts a date into a string

(f/format (Date. 0) "HH MM dd Z" {:timezone "GMT" :cached true})
=> "00 01 01 +0000"

(f/format (common/calendar (Date. 0)
                           (TimeZone/getTimeZone "GMT"))
          "HH MM dd Z"
          {})
=> "00 01 01 +0000"

(f/format (Timestamp. 0)
          "HH MM dd Z"
          {:timezone "PST"})
=> "16 12 31 -0800"

(f/format (Date. 0) "HH MM dd Z")
=> string?
raw docstring

from-longclj

(from-long t)
(from-long t opts)

creates an instant from a long (-> (t/from-long 0 {:timezone "Asia/Kolkata" :type Calendar}) (t/to-map))

=> {:type java.util.GregorianCalendar, :timezone "Asia/Kolkata", :long 0 :year 1970, :month 1, :day 1, :hour 5, :minute 30 :second 0, :millisecond 0}

creates an instant from a long
(-> (t/from-long 0 {:timezone "Asia/Kolkata"
                    :type Calendar})
    (t/to-map))

=> {:type java.util.GregorianCalendar,
    :timezone "Asia/Kolkata", :long 0
    :year 1970, :month 1, :day 1,
   :hour 5, :minute 30 :second 0, :millisecond 0}
raw docstring

from-mapclj

(from-map t)
(from-map t opts)
(from-map t {:keys [type timezone] :as opts} fill)

creates an map from an instant (t/from-map {:type java.util.GregorianCalendar, :timezone "Asia/Kolkata", :long 0 :year 1970, :month 1, :day 1, :hour 5, :minute 30 :second 0, :millisecond 0}

        {:timezone "Asia/Kolkata"
         :type Date})

=> #inst "1970-01-01T00:00:00.000-00:00"

creates an map from an instant
(t/from-map {:type java.util.GregorianCalendar,
             :timezone "Asia/Kolkata", :long 0
             :year 1970, :month 1, :day 1,
             :hour 5, :minute 30 :second 0, :millisecond 0}

            {:timezone "Asia/Kolkata"
             :type Date})
=> #inst "1970-01-01T00:00:00.000-00:00"
raw docstring

get-timezoneclj

(get-timezone t)

returns the contained timezone if exists (t/get-timezone 0) => nil

(t/get-timezone (common/calendar (Date. 0) (TimeZone/getTimeZone "EST"))) => "EST"

returns the contained timezone if exists
(t/get-timezone 0) => nil

(t/get-timezone (common/calendar (Date. 0)
                                 (TimeZone/getTimeZone "EST")))
=> "EST"
raw docstring

has-timezone?clj

(has-timezone? t)

checks if the instance contains a timezone (t/has-timezone? 0) => false

(t/has-timezone? (common/calendar (Date. 0) (TimeZone/getDefault))) => true

checks if the instance contains a timezone
(t/has-timezone? 0) => false

(t/has-timezone? (common/calendar (Date. 0)
                                  (TimeZone/getDefault)))
=> true
raw docstring

hourclj

(hour t)
(hour t opts)

accesses the hour representated by the instant (t/hour 0 {:timezone "GMT"}) => 0

(t/hour (Date. 0) {:timezone "Asia/Kolkata"}) => 5

accesses the hour representated by the instant
(t/hour 0 {:timezone "GMT"}) => 0

(t/hour (Date. 0) {:timezone "Asia/Kolkata"}) => 5
raw docstring

instant?clj

(instant? obj)

checks if an object implements the instant protocol (t/instant? 0) => true

(t/instant? (Date.)) => true

checks if an object implements the instant protocol
(t/instant? 0) => true

(t/instant? (Date.)) => true
raw docstring

latestclj

(latest t1 t2 & more)

returns the latest date out of a range of inputs (t/latest (Date. 0) (Date. 1000) (Date. 20000)) => #inst "1970-01-01T00:00:20.000-00:00"

returns the latest date out of a range of inputs
(t/latest (Date. 0) (Date. 1000) (Date. 20000))
=> #inst "1970-01-01T00:00:20.000-00:00"
raw docstring

local-timezoneclj

(local-timezone)

returns the current timezone as a string

(local-timezone) => "Asia/Ho_Chi_Minh"

returns the current timezone as a string

(local-timezone)
=> "Asia/Ho_Chi_Minh"
raw docstring

millisecondclj

(millisecond t)
(millisecond t opts)

accesses the millisecond representated by the instant (t/millisecond 1010 {:timezone "GMT"}) => 10

accesses the millisecond representated by the instant
(t/millisecond 1010 {:timezone "GMT"}) => 10
raw docstring

minusclj

(minus t duration)
(minus t duration opts)

substracts a duration from the time (t/minus (Date. 0) {:years 1}) => #inst "1969-01-01T00:00:00.000-00:00"

(-> (t/from-map {:type java.time.ZonedDateTime :timezone "GMT", :year 1970, :month 1, :day 1, :hour 0, :minute 0, :second 0, :millisecond 0}) (t/minus {:years 10 :months 1 :weeks 4 :days 2}) (t/to-map {:timezone "GMT"})) => {:type java.time.ZonedDateTime, :timezone "GMT", :long -320803200000 :year 1959, :month 11, :day 2, :hour 0, :minute 0, :second 0, :millisecond 0}

substracts a duration from the time
(t/minus (Date. 0) {:years 1})
=> #inst "1969-01-01T00:00:00.000-00:00"

(-> (t/from-map {:type java.time.ZonedDateTime
                 :timezone "GMT",
                 :year 1970, :month 1, :day 1,
                 :hour 0, :minute 0, :second 0, :millisecond 0})
    (t/minus    {:years 10 :months 1 :weeks 4 :days 2})
    (t/to-map {:timezone "GMT"}))
=> {:type java.time.ZonedDateTime, :timezone "GMT",
    :long -320803200000
    :year 1959, :month 11, :day 2,
    :hour 0, :minute 0, :second 0, :millisecond 0}
raw docstring

minuteclj

(minute t)
(minute t opts)

accesses the minute representated by the instant (t/minute 0 {:timezone "GMT"}) => 0

(t/minute (Date. 0) {:timezone "Asia/Kolkata"}) => 30

accesses the minute representated by the instant
(t/minute 0 {:timezone "GMT"}) => 0

(t/minute (Date. 0) {:timezone "Asia/Kolkata"}) => 30
raw docstring

monthclj

(month t)
(month t opts)

accesses the month representated by the instant (t/month 0 {:timezone "GMT"}) => 1

accesses the month representated by the instant
(t/month 0 {:timezone "GMT"}) => 1
raw docstring

nowclj

(now)
(now opts)

returns the current datetime (t/now) ;; => #(instance? (t/default-type) %)

(t/now {:type Date}) => #(instance? Date %)

(t/now {:type Calendar}) => #(instance? Calendar %)

returns the current datetime
(t/now)
;; => #(instance? (t/default-type) %)

(t/now {:type Date})
=> #(instance? Date %)

(t/now {:type Calendar})
=> #(instance? Calendar %)
raw docstring

parseclj

(parse s pattern)
(parse s pattern {:keys [cached] :as opts})

converts a string into a date (f/parse "00 00 01 01 01 1989 +0000" "ss mm HH dd MM yyyy Z" {:type Date :timezone "GMT"}) => #inst "1989-01-01T01:00:00.000-00:00"

(-> (f/parse "00 00 01 01 01 1989 -0800" "ss mm HH dd MM yyyy Z" {:type Calendar}) (map/to-map {:timezone "GMT"} common/+default-keys+)) => {:type java.util.GregorianCalendar, :timezone "GMT", :long 599648400000, :year 1989, :month 1, :day 1, :hour 9, :minute 0, :second 0, :millisecond 0}

(-> (f/parse "00 00 01 01 01 1989 +0000" "ss mm HH dd MM yyyy Z" {:type Timestamp}) (map/to-map {:timezone "Asia/Kolkata"} common/+default-keys+)) => {:type java.sql.Timestamp, :timezone "Asia/Kolkata", :long 599619600000, :year 1989, :month 1, :day 1, :hour 6, :minute 30, :second 0, :millisecond 0}

converts a string into a date
(f/parse "00 00 01 01 01 1989 +0000"
         "ss mm HH dd MM yyyy Z"
         {:type Date :timezone "GMT"})
=> #inst "1989-01-01T01:00:00.000-00:00"

(-> (f/parse "00 00 01 01 01 1989 -0800"
             "ss mm HH dd MM yyyy Z"
             {:type Calendar})
    (map/to-map {:timezone "GMT"}
                common/+default-keys+))
=> {:type java.util.GregorianCalendar,
    :timezone "GMT",
    :long 599648400000,
    :year 1989,
    :month 1, :day 1,
    :hour 9, :minute 0,
    :second 0, :millisecond 0}


(-> (f/parse "00 00 01 01 01 1989 +0000"
             "ss mm HH dd MM yyyy Z"
             {:type Timestamp})
    (map/to-map {:timezone "Asia/Kolkata"}
                common/+default-keys+))
=> {:type java.sql.Timestamp,
   :timezone "Asia/Kolkata",
    :long 599619600000,
    :year 1989,
    :month 1, :day 1,
    :hour 6, :minute 30,
    :second 0, :millisecond 0}

raw docstring

plusclj

(plus t duration)
(plus t duration opts)

adds a duration to the time (t/plus (Date. 0) {:weeks 2}) => #inst "1970-01-15T00:00:00.000-00:00"

(t/plus (Date. 0) 1000) => #inst "1970-01-01T00:00:01.000-00:00"

(t/plus (java.util.Date. 0) {:years 10 :months 1 :weeks 4 :days 2}) => #inst "1980-03-02T00:00:00.000-00:00"

adds a duration to the time
(t/plus (Date. 0) {:weeks 2})
=> #inst "1970-01-15T00:00:00.000-00:00"

(t/plus (Date. 0) 1000)
=> #inst "1970-01-01T00:00:01.000-00:00"

(t/plus (java.util.Date. 0)
        {:years 10 :months 1 :weeks 4 :days 2})
=> #inst "1980-03-02T00:00:00.000-00:00"
raw docstring

representation?clj

(representation? obj)

checks if an object implements the representation protocol (t/representation? 0) => false

(t/representation? (common/calendar (Date. 0) (TimeZone/getTimeZone "GMT"))) => true

checks if an object implements the representation protocol
(t/representation? 0) => false

(t/representation? (common/calendar (Date. 0) (TimeZone/getTimeZone "GMT")))
=> true
raw docstring

secondclj

(second t)
(second t opts)

accesses the second representated by the instant (t/second 1000 {:timezone "GMT"}) => 1

accesses the second representated by the instant
(t/second 1000 {:timezone "GMT"}) => 1
raw docstring

time-metaclj

(time-meta cls)

retrieves the meta-data for the time object (t/time-meta TimeZone) => {:base :zone}

retrieves the meta-data for the time object
(t/time-meta TimeZone)
=> {:base :zone}
raw docstring

to-lengthclj

(to-length t)
(to-length t rep)

converts a object implementing IDuration to a long (t/to-length {:days 1}) => 86400000

converts a object implementing IDuration to a long
(t/to-length {:days 1})
=> 86400000
raw docstring

to-longclj

(to-long t)

gets the long representation for the instant (t/to-long #inst "1970-01-01T00:00:10.000-00:00") => 10000

gets the long representation for the instant
(t/to-long #inst "1970-01-01T00:00:10.000-00:00")
=> 10000
raw docstring

to-mapclj

(to-map t)
(to-map t opts)
(to-map t {:keys [timezone] :as opts} ks)

creates an map from an instant (-> (t/from-long 0 {:timezone "Asia/Kolkata" :type Date}) (t/to-map {:timezone "GMT"} [:year :month :day])) => {:type java.util.Date, :timezone "GMT", :long 0, :year 1970, :month 1, :day 1}

creates an map from an instant
(-> (t/from-long 0 {:timezone "Asia/Kolkata"
                    :type Date})
    (t/to-map {:timezone "GMT"} [:year :month :day]))
=> {:type java.util.Date, :timezone "GMT", :long 0,
    :year 1970, :month 1, :day 1}
raw docstring

to-vectorclj

(to-vector t {:keys [timezone] :as opts} ks)

converts an instant to an array representation (to-vector 0 {:timezone "GMT"} :all) => [1970 1 1 0 0 0 0]

(to-vector (Date. 0) {:timezone "GMT"} :day) => [1970 1 1]

(to-vector (common/calendar (Date. 0) (TimeZone/getTimeZone "EST")) {} [:month :day :year]) => [12 31 1969]

(to-vector (common/calendar (Date. 0) (TimeZone/getTimeZone "EST")) {:timezone "GMT"} [:month :day :year]) => [1 1 1970]

converts an instant to an array representation
(to-vector 0 {:timezone "GMT"} :all)
=> [1970 1 1 0 0 0 0]

(to-vector (Date. 0) {:timezone "GMT"} :day)
=> [1970 1 1]

(to-vector (common/calendar (Date. 0)
                            (TimeZone/getTimeZone "EST"))
           {}
           [:month :day :year])
=> [12 31 1969]

(to-vector (common/calendar (Date. 0)
                            (TimeZone/getTimeZone "EST"))
           {:timezone "GMT"}
           [:month :day :year])
=> [1 1 1970]
raw docstring

truncateclj

(truncate t col)
(truncate t col opts)

truncates the time to a particular field (t/truncate #inst "1989-12-28T12:34:00.000-00:00" :hour {:timezone "GMT"}) => #inst "1989-12-28T12:00:00.000-00:00"

(t/truncate #inst "1989-12-28T12:34:00.000-00:00" :year {:timezone "GMT"}) => #inst "1989-01-01T00:00:00.000-00:00"

truncates the time to a particular field
(t/truncate #inst "1989-12-28T12:34:00.000-00:00"
            :hour {:timezone "GMT"})
=> #inst "1989-12-28T12:00:00.000-00:00"

(t/truncate #inst "1989-12-28T12:34:00.000-00:00"
            :year {:timezone "GMT"})
=> #inst "1989-01-01T00:00:00.000-00:00"
raw docstring

with-timezoneclj

(with-timezone t tz)

returns the same instance in a different timezone (t/with-timezone 0 "EST") => 0

returns the same instance in a different timezone
(t/with-timezone 0 "EST") => 0
raw docstring

wrap-proxyclj

(wrap-proxy f)

converts one representation to another via a third object, used by java.sql.Timestamp and others

converts one representation to another via a third object,
used by java.sql.Timestamp and others
raw docstring

yearclj

(year t)
(year t opts)

accesses the year representated by the instant (t/year 0 {:timezone "GMT"}) => 1970

(t/year (Date. 0) {:timezone "EST"}) => 1969

accesses the year representated by the instant
(t/year 0 {:timezone "GMT"}) => 1970

(t/year (Date. 0) {:timezone "EST"}) => 1969
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close