clj-duckling.util.time
->fields
(->fields {:keys [start], :as t})
add-to-period
(add-to-period p grain n)
Adds the given quantity of grain to the period
day-of-week
(day-of-week t)
Returns the day of week of a time grain
days-in-month
(days-in-month tt)
Returns the number of days in the month of tt
end
(end {:keys [start grain end], :as t})
Returns the end *instant* of the time object
intersect
(intersect t1 t2)
With the special case of time grains, it's quite easy. Will need to generalize to
intervals later. Returns nil if no intersection.
The result grain is the smallest of the args grains.
interval
(interval t1 t2)
Builds a time interval between start of t1 and *start* of t2.
The grain is the smallest of the args.
interval-start-end
(interval-start-end t1 t2)
Builds a time interval between start of t1 and *end* of t2.
The grain is the smallest of the args.
month
(month t)
Returns the month of a time grain
negative-period
(negative-period period)
Turn a period into its opposite sign
period
(period grain n)
Creates a period object with the given grain and quantity (can be negative)
period->duration
(period->duration period)
Convert a period into an amount of seconds. This is approximate, since for
instance 1 month's duration in seconds depends on which month
period-grain
(period-grain period)
Returns the grain of the period (the finest of its grains)
plus
(plus tt grain n)
Add n grain to tt.
Set the grain to the finest between tt's and the added one.
plus-period
(plus-period tt period)
Adds the period to the time object. The resulting grain is the finest.
round
(round tt grain)
Rounds the time grain to the grain: all smaller grain fields set to 0.
If applied to a true interval (with :end), it turns the interval into
a grain time objects (rounds start, removes :end).
start-before-the-end-of?
(start-before-the-end-of? t1 t2)
starting-at-the-end-of
(starting-at-the-end-of tt)
Build a time that starts at the end of provided time, with same grain
t
(t timezone year)
(t timezone year month)
(t timezone year month day)
(t timezone year month day hour)
(t timezone year month day hour minute)
(t timezone year month day hour minute second)
(t grain timezone year month day hour minute second)
Builds a time object with timezone, start and grain.
Timezone is actually extracted from the provided instant.
valid?
(valid? {:keys [start grain end], :as t})
year
(year t)
Returns the year of the start of a time grain