Added compiled JavaScript to repository for GitHub pages
This feels like a mistake...
This commit is contained in:
parent
3d5a2fb322
commit
dc226b1f25
468 changed files with 212152 additions and 2 deletions
759
resources/public/js/compiled/out/cljs_time/core.cljs
Normal file
759
resources/public/js/compiled/out/cljs_time/core.cljs
Normal file
|
|
@ -0,0 +1,759 @@
|
|||
(ns cljs-time.core
|
||||
"### The core namespace for date-time operations in the cljs-time library.
|
||||
|
||||
Create a DateTime instance with date-time (or a local DateTime instance with local-date-time),
|
||||
specifying the year, month, day, hour, minute, second, and millisecond:
|
||||
|
||||
=> (date-time 1986 10 14 4 3 27 456)
|
||||
#<DateTime 1986-10-14T04:03:27.456Z>
|
||||
|
||||
=> (local-date-time 1986 10 14 4 3 27 456)
|
||||
#<DateTime 1986-10-14T04:03:27.456>
|
||||
|
||||
Less-significant fields can be omitted:
|
||||
|
||||
=> (date-time 1986 10 14)
|
||||
#<DateTime 1986-10-14T00:00:00.000Z>
|
||||
|
||||
=> (local-date-time 1986 10 14)
|
||||
#<DateTime 1986-10-14T00:00:00.000>
|
||||
|
||||
Get the current time with (now) and the start of the Unix epoch with (epoch).
|
||||
|
||||
Once you have a date-time, use accessors like hour and second to access the
|
||||
corresponding fields:
|
||||
|
||||
=> (hour (date-time 1986 10 14 22))
|
||||
22
|
||||
|
||||
=> (hour (local-date-time 1986 10 14 22))
|
||||
22
|
||||
|
||||
The functions after? and before? determine the relative position of two
|
||||
DateTime instances:
|
||||
|
||||
=> (after? (date-time 1986 10) (date-time 1986 9))
|
||||
true
|
||||
|
||||
=> (after? (local-date-time 1986 10) (local-date-time 1986 9))
|
||||
true
|
||||
|
||||
Often you will want to find a date some amount of time from a given date. For
|
||||
example, to find the time 1 month and 3 weeks from a given date-time:
|
||||
|
||||
=> (plus (date-time 1986 10 14) (months 1) (weeks 3))
|
||||
#<DateTime 1986-12-05T00:00:00.000Z>
|
||||
|
||||
=> (plus (local-date-time 1986 10 14) (months 1) (weeks 3))
|
||||
#<DateTime 1986-12-05T00:00:00.000Z>
|
||||
|
||||
An Interval is used to represent the span of time between two DateTime
|
||||
instances. Construct one using interval, then query them using within?,
|
||||
overlaps?, and abuts?
|
||||
|
||||
=> (within? (interval (date-time 1986) (date-time 1990)) (date-time 1987))
|
||||
true
|
||||
|
||||
To find the amount of time encompased by an interval, use in-seconds and
|
||||
in-minutes:
|
||||
|
||||
=> (in-minutes (interval (date-time 1986 10 2) (date-time 1986 10 14)))
|
||||
17280
|
||||
|
||||
Note that all functions in this namespace work with Joda objects or ints. If
|
||||
you need to print or parse date-times, see cljs-time.format. If you need to
|
||||
ceorce date-times to or from other types, see cljs-time.coerce."
|
||||
(:refer-clojure :exclude [= extend second])
|
||||
(:require
|
||||
[cljs-time.internal.core :as internal :refer [leap-year? format]]
|
||||
[clojure.string :as string]
|
||||
goog.date.Interval)
|
||||
(:import
|
||||
goog.date.Date
|
||||
goog.date.DateTime
|
||||
goog.date.UtcDateTime))
|
||||
|
||||
(def ^{:doc "**Note:** Equality in goog.date.* (and also with plain
|
||||
javascript dates) is not the same as in Joda/clj-time. Two date
|
||||
objects representing the same instant in time in goog.date.* are not
|
||||
equal.
|
||||
|
||||
If you need to test for equality use either `cljs-time.core/=`, or
|
||||
optionally you can require the `cljs-time.extend` namespace which will
|
||||
extend the goog.date.* datatypes, so that clojure.core/= works as
|
||||
expected."}
|
||||
= cljs-time.internal.core/=)
|
||||
|
||||
(defprotocol DateTimeProtocol
|
||||
"Interface for various date time functions"
|
||||
(year [this] "Return the year component of the given date/time.")
|
||||
(month [this] "Return the month component of the given date/time.")
|
||||
(day [this] "Return the day of month component of the given date/time.")
|
||||
(day-of-week [this] "Return the day of week component of the given date/time. Monday is 1 and Sunday is 7")
|
||||
(hour [this] "Return the hour of day component of the given date/time. A time of 12:01am will have an hour component of 0.")
|
||||
(minute [this] "Return the minute of hour component of the given date/time.")
|
||||
(sec [this] "Return the second of minute component of the given date/time.")
|
||||
(second [this] "Return the second of minute component of the given date/time.")
|
||||
(milli [this] "Return the millisecond of second component of the given date/time.")
|
||||
(equal? [this that] "Returns true if DateTime 'this' is strictly equal to date/time 'that'.")
|
||||
(after? [this that] "Returns true if DateTime 'this' is strictly after date/time 'that'.")
|
||||
(before? [this that] "Returns true if DateTime 'this' is strictly before date/time 'that'.")
|
||||
(plus- [this period] "Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).")
|
||||
(minus- [this period] "Returns a new date/time corresponding to the given date/time moved backwards by the given Period(s).")
|
||||
(first-day-of-the-month- [this] "Returns the first day of the month")
|
||||
(last-day-of-the-month- [this] "Returns the last day of the month"))
|
||||
|
||||
(defprotocol InTimeUnitProtocol
|
||||
"Interface for in-<time unit> functions"
|
||||
(in-millis [this] "Return the time in milliseconds.")
|
||||
(in-seconds [this] "Return the time in seconds.")
|
||||
(in-minutes [this] "Return the time in minutes.")
|
||||
(in-hours [this] "Return the time in hours.")
|
||||
(in-days [this] "Return the time in days.")
|
||||
(in-weeks [this] "Return the time in weeks")
|
||||
(in-months [this] "Return the time in months")
|
||||
(in-years [this] "Return the time in years"))
|
||||
|
||||
(defrecord Interval [start end])
|
||||
|
||||
(defn interval
|
||||
"Returns an Interval representing the span between the two given DateTime.
|
||||
Note that intervals are closed on the left and open on the right."
|
||||
[start end]
|
||||
{:pre [(<= (.getTime start) (.getTime end))]}
|
||||
(->Interval start end))
|
||||
|
||||
(defrecord Period [years months weeks days hours minutes seconds millis])
|
||||
|
||||
(defn period
|
||||
([period value]
|
||||
(map->Period {period value}))
|
||||
([p1 v1 & kvs]
|
||||
(apply assoc (period p1 v1) kvs)))
|
||||
|
||||
(def periods
|
||||
(let [fixed-time-fn (fn [f set-fn op date value]
|
||||
(let [date (.clone date)]
|
||||
(when value (set-fn date (op (f date) value)))
|
||||
date))]
|
||||
{:millis (partial fixed-time-fn milli #(.setMilliseconds %1 %2))
|
||||
:seconds (partial fixed-time-fn second #(.setSeconds %1 %2))
|
||||
:minutes (partial fixed-time-fn minute #(.setMinutes %1 %2))
|
||||
:hours (partial fixed-time-fn hour #(.setHours %1 %2))
|
||||
:days (partial fixed-time-fn day #(.setDate %1 %2))
|
||||
:weeks (fn [op date value]
|
||||
(let [date (.clone date)]
|
||||
(when value (.setDate date (op (day date) (* 7 value))))
|
||||
date))
|
||||
:months (fn [op date value]
|
||||
(let [date (.clone date)]
|
||||
(when value
|
||||
(let [m (op 0 value)
|
||||
i (goog.date.Interval. goog.date.Interval.MONTHS m)]
|
||||
(.add date i)))
|
||||
date))
|
||||
:years (fn [op date value]
|
||||
(let [date (.clone date)]
|
||||
(when value
|
||||
(if (and (leap-year? (year date))
|
||||
(= 2 (month date))
|
||||
(= 29 (day date)))
|
||||
(.setDate date 28))
|
||||
(.setYear date (op (year date) value)))
|
||||
date))}))
|
||||
|
||||
(defn period-fn [p]
|
||||
(fn [operator date]
|
||||
(reduce (fn [d [k v]] ((periods k) operator d v)) date p)))
|
||||
|
||||
(extend-protocol DateTimeProtocol
|
||||
goog.date.UtcDateTime
|
||||
(year [this] (.getYear this))
|
||||
(month [this] (inc (.getMonth this)))
|
||||
(day [this] (.getDate this))
|
||||
(day-of-week [this] (let [d (.getDay this)] (if (= d 0) 7 d)))
|
||||
(hour [this] (.getHours this))
|
||||
(minute [this] (.getMinutes this))
|
||||
(second [this] (.getSeconds this))
|
||||
(milli [this] (.getMilliseconds this))
|
||||
(equal? [this that] (== (.getTime this) (.getTime that)))
|
||||
(after? [this that] (> (.getTime this) (.getTime that)))
|
||||
(before? [this that] (< (.getTime this) (.getTime that)))
|
||||
(plus- [this period] ((period-fn period) + this))
|
||||
(minus- [this period] ((period-fn period) - this))
|
||||
(first-day-of-the-month- [this]
|
||||
(goog.date.UtcDateTime. (.getYear this) (.getMonth this) 1 0 0 0 0))
|
||||
(last-day-of-the-month- [this]
|
||||
(minus-
|
||||
(goog.date.UtcDateTime. (.getYear this) (inc (.getMonth this)) 1 0 0 0 0)
|
||||
(period :days 1)))
|
||||
|
||||
goog.date.DateTime
|
||||
(year [this] (.getYear this))
|
||||
(month [this] (inc (.getMonth this)))
|
||||
(day [this] (.getDate this))
|
||||
(day-of-week [this] (let [d (.getDay this)] (if (= d 0) 7 d)))
|
||||
(hour [this] (.getHours this))
|
||||
(minute [this] (.getMinutes this))
|
||||
(second [this] (.getSeconds this))
|
||||
(milli [this] (.getMilliseconds this))
|
||||
(equal? [this that] (== (.getTime this) (.getTime that)))
|
||||
(after? [this that] (> (.getTime this) (.getTime that)))
|
||||
(before? [this that] (< (.getTime this) (.getTime that)))
|
||||
(plus- [this period] ((period-fn period) + this))
|
||||
(minus- [this period] ((period-fn period) - this))
|
||||
(first-day-of-the-month- [this]
|
||||
(goog.date.DateTime. (.getYear this) (.getMonth this) 1 0 0 0 0))
|
||||
(last-day-of-the-month- [this]
|
||||
(minus-
|
||||
(goog.date.DateTime. (.getYear this) (inc (.getMonth this)) 1 0 0 0 0)
|
||||
(period :days 1)))
|
||||
|
||||
goog.date.Date
|
||||
(year [this] (.getYear this))
|
||||
(month [this] (inc (.getMonth this)))
|
||||
(day [this] (.getDate this))
|
||||
(day-of-week [this] (let [d (.getDay this)] (if (= d 0) 7 d)))
|
||||
(hour [this] nil)
|
||||
(minute [this] nil)
|
||||
(second [this] nil)
|
||||
(milli [this] nil)
|
||||
(equal? [this that] (== (.getTime this) (.getTime that)))
|
||||
(after? [this that] (> (.getTime this) (.getTime that)))
|
||||
(before? [this that] (< (.getTime this) (.getTime that)))
|
||||
(plus- [this period] ((period-fn period) + this))
|
||||
(minus- [this period] ((period-fn period) - this))
|
||||
(first-day-of-the-month- [this]
|
||||
(goog.date.Date. (.getYear this) (.getMonth this) 1))
|
||||
(last-day-of-the-month- [this]
|
||||
(minus-
|
||||
(goog.date.Date. (.getYear this) (inc (.getMonth this)) 1)
|
||||
(period :days 1))))
|
||||
|
||||
(def utc #js {:id "UTC" :std_offset 0 :names ["UTC"] :transitions []})
|
||||
|
||||
(defn default-ms-fn []
|
||||
(fn [] (js/Date.now)))
|
||||
|
||||
(defn offset-ms-fn
|
||||
[offset]
|
||||
(fn [] (+ (js/Date.now) offset)))
|
||||
|
||||
(defn static-ms-fn
|
||||
[ms]
|
||||
(fn [] ms))
|
||||
|
||||
(def ^:dynamic *ms-fn* (default-ms-fn))
|
||||
|
||||
(defn now
|
||||
"Returns a DateTime for the current instant in the UTC time zone."
|
||||
[]
|
||||
(doto (goog.date.UtcDateTime.) (.setTime (*ms-fn*))))
|
||||
|
||||
(defn time-now
|
||||
"Returns a local DateTime for the current instant without date or time zone
|
||||
in the current time zone."
|
||||
[]
|
||||
(doto (goog.date.DateTime.) (.setTime (*ms-fn*))))
|
||||
|
||||
(defn at-midnight [datetime]
|
||||
(let [datetime (.clone datetime)]
|
||||
(doto datetime
|
||||
(.setHours 0)
|
||||
(.setMinutes 0)
|
||||
(.setSeconds 0)
|
||||
(.setMilliseconds 0))))
|
||||
|
||||
(defn today-at-midnight
|
||||
"Returns a DateTime for today at midnight in the UTC time zone."
|
||||
[]
|
||||
(at-midnight (now)))
|
||||
|
||||
(defn epoch
|
||||
"Returns a DateTime for the begining of the Unix epoch in the UTC time zone."
|
||||
[]
|
||||
(doto (goog.date.UtcDateTime.) (.setTime 0)))
|
||||
|
||||
(defn date-midnight
|
||||
"Constructs and returns a new DateTime at midnight in UTC.
|
||||
|
||||
Specify the year, month of year, day of month. Note that month and day are
|
||||
1-indexed. Any number of least-significant components can be ommited, in
|
||||
which case they will default to 1."
|
||||
([year]
|
||||
(date-midnight year 1 1))
|
||||
([year month]
|
||||
(date-midnight year month 1))
|
||||
([year month day]
|
||||
(goog.date.UtcDateTime. year (dec month) day)))
|
||||
|
||||
(defn date-time
|
||||
"Constructs and returns a new DateTime in UTC.
|
||||
|
||||
Specify the year, month of year, day of month, hour of day, minute if hour,
|
||||
second of minute, and millisecond of second. Note that month and day are
|
||||
1-indexed while hour, second, minute, and millis are 0-indexed.
|
||||
|
||||
Any number of least-significant components can be ommited, in which case
|
||||
they will default to 1 or 0 as appropriate."
|
||||
([year]
|
||||
(date-time year 1 1 0 0 0 0))
|
||||
([year month]
|
||||
(date-time year month 1 0 0 0 0))
|
||||
([year month day]
|
||||
(date-time year month day 0 0 0 0))
|
||||
([year month day hour]
|
||||
(date-time year month day hour 0 0 0))
|
||||
([year month day hour minute]
|
||||
(date-time year month day hour minute 0 0))
|
||||
([year month day hour minute second]
|
||||
(date-time year month day hour minute second 0))
|
||||
([year month day hour minute second millis]
|
||||
(goog.date.UtcDateTime. year (dec month) day hour minute second millis)))
|
||||
|
||||
(defn local-date-time
|
||||
"Constructs and returns a new local DateTime.
|
||||
Specify the year, month of year, day of month, hour of day, minute of hour,
|
||||
second of minute, and millisecond of second. Note that month and day are
|
||||
1-indexed while hour, second, minute, and millis are 0-indexed.
|
||||
Any number of least-significant components can be ommited, in which case
|
||||
they will default to 1 or 0 as appropriate."
|
||||
([year]
|
||||
(local-date-time year 1 1 0 0 0 0))
|
||||
([year month]
|
||||
(local-date-time year month 1 0 0 0 0))
|
||||
([year month day]
|
||||
(local-date-time year month day 0 0 0 0))
|
||||
([year month day hour]
|
||||
(local-date-time year month day hour 0 0 0))
|
||||
([year month day hour minute]
|
||||
(local-date-time year month day hour minute 0 0))
|
||||
([year month day hour minute second]
|
||||
(local-date-time year month day hour minute second 0))
|
||||
([year month day hour minute second millis]
|
||||
(goog.date.DateTime. year (dec month) day hour minute second millis)))
|
||||
|
||||
(defn local-date
|
||||
"Constructs and returns a new local DateTime.
|
||||
Specify the year, month, and day. Does not deal with timezones."
|
||||
[year month day]
|
||||
(goog.date.Date. year (dec month) day))
|
||||
|
||||
(defn today
|
||||
"Constructs and returns a new local DateTime representing today's date.
|
||||
local DateTime objects do not deal with timezones at all."
|
||||
[]
|
||||
(doto (goog.date.Date.) (.setTime (*ms-fn*))))
|
||||
|
||||
(defn time-zone-for-offset
|
||||
"Returns a timezone map for the given offset, specified either in hours or
|
||||
hours and minutes."
|
||||
([hours]
|
||||
(time-zone-for-offset hours nil))
|
||||
([hours minutes]
|
||||
(let [sign (if (neg? hours) :- :+)
|
||||
fmt (str "UTC%s%02d" (when minutes ":%02d"))
|
||||
hours (if (neg? hours) (* -1 hours) hours)
|
||||
tz-name (if minutes
|
||||
(format fmt (name sign) hours minutes)
|
||||
(format fmt (name sign) hours))]
|
||||
(with-meta
|
||||
{:id tz-name
|
||||
:offset [sign hours (or minutes 0) 0]
|
||||
:rules "-"
|
||||
:names [tz-name]}
|
||||
{:type ::time-zone}))))
|
||||
|
||||
(defn default-time-zone
|
||||
"Returns the default timezone map for the current environment."
|
||||
[]
|
||||
(let [offset (.getTimezoneOffset
|
||||
(doto (goog.date.DateTime.) (.setTime (*ms-fn*))))
|
||||
hours (/ (* -1 offset) 60)]
|
||||
(time-zone-for-offset (int hours) (mod hours 1))))
|
||||
|
||||
(defn to-default-time-zone
|
||||
"Assuming `dt` is in the UTC timezone, returns a DateTime
|
||||
corresponding to the same absolute instant in time as the given
|
||||
DateTime, but with calendar fields corresponding to in the default
|
||||
(local) timezone."
|
||||
[dt]
|
||||
(goog.date.DateTime. dt))
|
||||
|
||||
(defn from-default-time-zone
|
||||
"Assuming `dt` is in the UTC timezone, returns a DateTime
|
||||
corresponding to the same point in calendar time as the given
|
||||
DateTime, but for a correspondingly different absolute instant in
|
||||
time in the default (local) timezone.
|
||||
|
||||
Note: This implementation uses the ECMAScript 5.1 implementation which
|
||||
trades some historical daylight savings transition accuracy for simplicity.
|
||||
see http://es5.github.io/#x15.9.1.8
|
||||
"
|
||||
[dt]
|
||||
(goog.date.DateTime. (.getYear dt)
|
||||
(.getMonth dt)
|
||||
(.getDate dt)
|
||||
(.getHours dt)
|
||||
(.getMinutes dt)
|
||||
(.getSeconds dt)
|
||||
(.getMilliseconds dt)))
|
||||
|
||||
(defn years
|
||||
"Given a number, returns a Period representing that many years.
|
||||
Without an argument, returns a Period representing only years."
|
||||
([] (years nil))
|
||||
([n] (period :years n)))
|
||||
|
||||
(defn months
|
||||
"Given a number, returns a Period representing that many months.
|
||||
Without an argument, returns a Period representing only months."
|
||||
([] (months nil))
|
||||
([n] (period :months n)))
|
||||
|
||||
(defn weeks
|
||||
"Given a number, returns a Period representing that many weeks.
|
||||
Without an argument, returns a Period representing only weeks."
|
||||
([] (weeks nil))
|
||||
([n] (period :weeks n)))
|
||||
|
||||
(defn days
|
||||
"Given a number, returns a Period representing that many days.
|
||||
Without an argument, returns a Period representing only days."
|
||||
([] (days nil))
|
||||
([n] (period :days n)))
|
||||
|
||||
(defn hours
|
||||
"Given a number, returns a Period representing that many hours.
|
||||
Without an argument, returns a Period representing only hours."
|
||||
([] (hours nil))
|
||||
([n] (period :hours n)))
|
||||
|
||||
(defn minutes
|
||||
"Given a number, returns a Period representing that many minutes.
|
||||
Without an argument, returns a Period representing only minutes."
|
||||
([] (minutes nil))
|
||||
([n] (period :minutes n)))
|
||||
|
||||
(defn seconds
|
||||
"Given a number, returns a Period representing that many seconds.
|
||||
Without an argument, returns a Period representing only seconds."
|
||||
([] (seconds nil))
|
||||
([n] (period :seconds n)))
|
||||
|
||||
(defn millis
|
||||
"Given a number, returns a Period representing that many milliseconds.
|
||||
Without an argument, returns a Period representing only milliseconds."
|
||||
([] (millis nil))
|
||||
([n] (period :millis n)))
|
||||
|
||||
(defn plus
|
||||
"Returns a new date/time corresponding to the given date/time moved
|
||||
forwards by the given Period(s)."
|
||||
([dt p]
|
||||
(plus- dt p))
|
||||
([dt p & ps]
|
||||
(reduce plus- (plus- dt p) ps)))
|
||||
|
||||
(defn minus
|
||||
"Returns a new date/time object corresponding to the given date/time
|
||||
moved backwards by the given Period(s)."
|
||||
([dt p]
|
||||
(minus- dt p))
|
||||
([dt p & ps]
|
||||
(reduce minus- (minus- dt p) ps)))
|
||||
|
||||
(defn ago
|
||||
"Returns a DateTime a supplied period before the present.
|
||||
|
||||
e.g. `(-> 5 years ago)`"
|
||||
[period]
|
||||
(minus (now) period))
|
||||
|
||||
(defn yesterday
|
||||
"Returns a DateTime for yesterday relative to now"
|
||||
[]
|
||||
(-> 1 days ago))
|
||||
|
||||
(defn from-now
|
||||
"Returns a DateTime a supplied period after the present.
|
||||
e.g. `(-> 30 minutes from-now)`"
|
||||
[period]
|
||||
(plus (now) period))
|
||||
|
||||
(defn earliest
|
||||
"Returns the earliest of the supplied DateTimes"
|
||||
([dt1 dt2]
|
||||
(if (before? dt1 dt2) dt1 dt2))
|
||||
([dts]
|
||||
(reduce earliest dts)))
|
||||
|
||||
(defn latest
|
||||
"Returns the latest of the supplied DateTimes"
|
||||
([dt1 dt2]
|
||||
(if (after? dt1 dt2) dt1 dt2))
|
||||
([dts]
|
||||
(reduce latest dts)))
|
||||
|
||||
(defn start
|
||||
"Returns the start DateTime of an Interval."
|
||||
[in]
|
||||
(:start in))
|
||||
|
||||
(defn end
|
||||
"Returns the end DateTime of an Interval."
|
||||
[in]
|
||||
(:end in))
|
||||
|
||||
(defn extend
|
||||
"Returns an Interval with an end DateTime the specified Period after the end
|
||||
of the given Interval"
|
||||
[in & by]
|
||||
(assoc in :end (apply plus (end in) by)))
|
||||
|
||||
(defn- month-range [{:keys [start end]}]
|
||||
(->> (range)
|
||||
(map #(plus start (months (inc %))))
|
||||
(take-while #(not (after? % end)))))
|
||||
|
||||
(defn- total-days-in-whole-months [interval]
|
||||
(map #(.getNumberOfDaysInMonth %) (month-range interval)))
|
||||
|
||||
(defn- in-months-
|
||||
"Returns the number of months in the given Interval.
|
||||
|
||||
For example, the interval 2nd Jan 2012 midnight to 2nd Feb 2012 midnight,
|
||||
returns 1 month.
|
||||
|
||||
Likewise, 29th Dec 2011 midnight to 29th Feb 2012 midnight returns 2 months.
|
||||
|
||||
But also, 31st Dec 2011 midnight to 29th Feb 2012 midnight returns 2 months.
|
||||
|
||||
And, 28th Dec 2012 midnight to 28th Feb 2013 midnight returns 2 months."
|
||||
[{:keys [start end] :as interval}]
|
||||
(count (total-days-in-whole-months interval)))
|
||||
|
||||
(defn- in-years-
|
||||
"Returns the number of standard years in the given Interval."
|
||||
[{:keys [start end]}]
|
||||
(let [sm (month start) sd (day start)
|
||||
em (month end) ed (day end)
|
||||
d1 (cond (and (= sm 2) (= sd 29) (= em 2) (= ed 28)) 0
|
||||
(before? (date-time (year start) sm sd)
|
||||
(date-time (year start) em ed)) 0
|
||||
(after? (date-time (year start) sm sd)
|
||||
(date-time (year start) em ed)) 1
|
||||
:else-is-same-date 0)]
|
||||
(- (year end) (year start) d1)))
|
||||
|
||||
(defn conversion-error [from to]
|
||||
(let [from (string/capitalize (name from))
|
||||
to (name to)]
|
||||
(throw
|
||||
(ex-info (format "%s cannot be converted to %s" from to)
|
||||
{:type :unsupported-operation}))))
|
||||
|
||||
(extend-protocol InTimeUnitProtocol
|
||||
cljs-time.core.Period
|
||||
(in-millis [{:keys [millis seconds minutes hours days weeks months years]}]
|
||||
(cond months (conversion-error :months :millis)
|
||||
years (conversion-error :years :millis)
|
||||
:default (+ millis
|
||||
(* seconds 1000)
|
||||
(* minutes 60 1000)
|
||||
(* hours 60 60 1000)
|
||||
(* days 24 60 60 1000)
|
||||
(* weeks 7 24 60 60 1000))))
|
||||
(in-seconds [this] (int (/ (in-millis this) 1000)))
|
||||
(in-minutes [this] (int (/ (in-seconds this) 60)))
|
||||
(in-hours [this] (int (/ (in-minutes this) 60)))
|
||||
(in-days [this] (int (/ (in-hours this) 24)))
|
||||
(in-weeks [this] (int (/ (in-days this) 7)))
|
||||
(in-months [{:keys [millis seconds minutes hours days weeks months years]}]
|
||||
(cond millis (conversion-error :millis :months)
|
||||
seconds (conversion-error :seconds :months)
|
||||
minutes (conversion-error :minutes :months)
|
||||
hours (conversion-error :hours :months)
|
||||
days (conversion-error :days :months)
|
||||
weeks (conversion-error :weeks :months)
|
||||
months (+ months (* (or years 0) 12))
|
||||
years (* years 12)))
|
||||
(in-years [{:keys [millis seconds minutes hours days weeks months years]}]
|
||||
(cond millis (conversion-error :millis :years)
|
||||
seconds (conversion-error :seconds :years)
|
||||
minutes (conversion-error :minutes :years)
|
||||
hours (conversion-error :hours :years)
|
||||
days (conversion-error :days :years)
|
||||
weeks (conversion-error :weeks :years)
|
||||
months (int (+ (/ months 12) years))
|
||||
years years))
|
||||
cljs-time.core.Interval
|
||||
(in-millis [{:keys [start end]}] (- (.getTime end) (.getTime start)))
|
||||
(in-seconds [this] (int (/ (in-millis this) 1000)))
|
||||
(in-minutes [this] (int (/ (in-seconds this) 60)))
|
||||
(in-hours [this] (int (/ (in-minutes this) 60)))
|
||||
(in-days [this] (int (/ (in-hours this) 24)))
|
||||
(in-weeks [this] (int (/ (in-days this) 7)))
|
||||
(in-months [this] (in-months- this))
|
||||
(in-years [this] (in-years- this)))
|
||||
|
||||
(defn within?
|
||||
"With 2 arguments: Returns true if the given Interval contains the given
|
||||
DateTime. Note that if the DateTime is exactly equal to the
|
||||
end of the interval, this function returns false.
|
||||
|
||||
With 3 arguments: Returns true if the start DateTime is
|
||||
equal to or before and the end DateTime is equal to or after the test
|
||||
DateTime."
|
||||
([{:keys [start end]} date]
|
||||
(within? start end date))
|
||||
([start end date]
|
||||
(or (= start date)
|
||||
;(= end date)
|
||||
(and (before? start date) (after? end date)))))
|
||||
|
||||
(defn overlaps?
|
||||
"With 2 arguments: Returns true of the two given Intervals overlap.
|
||||
Note that intervals that satisfy abuts? do not satisfy overlaps?
|
||||
|
||||
With 4 arguments: Returns true if the range specified by start-a and end-a
|
||||
overlaps with the range specified by start-b and end-b."
|
||||
([{start-a :start end-a :end} {start-b :start end-b :end}]
|
||||
(and (not (or (= start-a end-b) (= end-a start-b)))
|
||||
(overlaps? start-a end-a start-b end-b)))
|
||||
([start-a end-a start-b end-b]
|
||||
(or (and (before? start-b end-a) (after? end-b start-a))
|
||||
(and (after? end-b start-a) (before? start-b end-a))
|
||||
(or (= start-a end-b) (= start-b end-a)))))
|
||||
|
||||
(defn abuts?
|
||||
"Returns true if Interval a abuts b, i.e. then end of a is exactly the
|
||||
beginning of b."
|
||||
[{start-a :start end-a :end} {start-b :start end-b :end}]
|
||||
(or (= start-a end-b) (= end-a start-b)))
|
||||
|
||||
(defn date? [x]
|
||||
(satisfies? DateTimeProtocol x))
|
||||
|
||||
(defn interval? [x]
|
||||
(instance? Interval x))
|
||||
|
||||
(defn period? [x]
|
||||
(instance? Period x))
|
||||
|
||||
(defn period-type? [type x]
|
||||
(and (period? x) (contains? x type)))
|
||||
|
||||
(defn years?
|
||||
"Returns true if the given value is an instance of Years"
|
||||
[val]
|
||||
(period-type? :years val))
|
||||
|
||||
(defn months?
|
||||
"Returns true if the given value is an instance of Months"
|
||||
[val]
|
||||
(period-type? :months val))
|
||||
|
||||
(defn weeks?
|
||||
"Returns true if the given value is an instance of Weeks"
|
||||
[val]
|
||||
(period-type? :weeks val))
|
||||
|
||||
(defn days?
|
||||
"Returns true if the given value is an instance of Days"
|
||||
[val]
|
||||
(period-type? :days val))
|
||||
|
||||
(defn hours?
|
||||
"Returns true if the given value is an instance of Hours"
|
||||
[val]
|
||||
(period-type? :hours val))
|
||||
|
||||
(defn minutes?
|
||||
"Returns true if the given value is an instance of Minutes"
|
||||
[val]
|
||||
(period-type? :minutes val))
|
||||
|
||||
(defn seconds?
|
||||
"Returns true if the given value is an instance of Seconds"
|
||||
[val]
|
||||
(period-type? :seconds val))
|
||||
|
||||
(defn mins-ago
|
||||
[d]
|
||||
(in-minutes (interval d (now))))
|
||||
|
||||
(defn last-day-of-the-month
|
||||
([dt]
|
||||
(last-day-of-the-month- dt))
|
||||
([year month]
|
||||
(last-day-of-the-month- (date-time year month))))
|
||||
|
||||
(defn number-of-days-in-the-month
|
||||
([dt]
|
||||
(number-of-days-in-the-month (year dt) (month dt)))
|
||||
([year month]
|
||||
(.getDate (last-day-of-the-month year month))))
|
||||
|
||||
(defn first-day-of-the-month
|
||||
([dt]
|
||||
(first-day-of-the-month- dt))
|
||||
([year month]
|
||||
(first-day-of-the-month- (date-time year month))))
|
||||
|
||||
|
||||
(defprotocol IToPeriod
|
||||
(->period [obj]))
|
||||
|
||||
(extend-protocol IToPeriod
|
||||
|
||||
cljs-time.core.Interval
|
||||
(->period [{:keys [start end] :as interval}]
|
||||
(let [years (in-years interval)
|
||||
start-year (year start)
|
||||
leap-years (count
|
||||
(remove false?
|
||||
(map leap-year?
|
||||
(range start-year (+ start-year years)))))
|
||||
start-month (month start)
|
||||
days-in-months (total-days-in-whole-months interval)
|
||||
months (- (count days-in-months) (* years 12))
|
||||
days-to-remove (reduce + days-in-months)
|
||||
days (- (in-days interval) days-to-remove)
|
||||
hours-to-remove (* 24 (+ days days-to-remove))
|
||||
hours (- (in-hours interval) hours-to-remove)
|
||||
minutes-to-remove (* 60 (+ hours hours-to-remove))
|
||||
minutes (- (in-minutes interval) minutes-to-remove)
|
||||
seconds-to-remove (* 60 (+ minutes minutes-to-remove))
|
||||
seconds (- (in-seconds interval) seconds-to-remove)]
|
||||
(period :years years
|
||||
:months months
|
||||
:days days
|
||||
:hours hours
|
||||
:minutes minutes
|
||||
:seconds seconds
|
||||
:millis (- (in-millis interval)
|
||||
(* 1000 (+ seconds seconds-to-remove))))))
|
||||
|
||||
cljs-time.core.Period
|
||||
(->period [period] period))
|
||||
|
||||
(defn today-at
|
||||
([hours minutes seconds millis]
|
||||
(let [midnight (doto (goog.date.Date.) (.setTime (*ms-fn*)))]
|
||||
(doto (goog.date.UtcDateTime. 0)
|
||||
(.setYear (.getYear midnight))
|
||||
(.setMonth (.getMonth midnight))
|
||||
(.setDate (.getDate midnight))
|
||||
(.setHours hours)
|
||||
(.setMinutes minutes)
|
||||
(.setSeconds seconds)
|
||||
(.setMilliseconds millis))))
|
||||
([hours minutes seconds]
|
||||
(today-at hours minutes seconds 0))
|
||||
([hours minutes]
|
||||
(today-at hours minutes 0)))
|
||||
|
||||
(defn do-at* [base-date-time body-fn]
|
||||
(binding [*ms-fn* (static-ms-fn (.getTime base-date-time))]
|
||||
(body-fn)))
|
||||
File diff suppressed because one or more lines are too long
3269
resources/public/js/compiled/out/cljs_time/core.js
Normal file
3269
resources/public/js/compiled/out/cljs_time/core.js
Normal file
File diff suppressed because it is too large
Load diff
1
resources/public/js/compiled/out/cljs_time/core.js.map
Normal file
1
resources/public/js/compiled/out/cljs_time/core.js.map
Normal file
File diff suppressed because one or more lines are too long
538
resources/public/js/compiled/out/cljs_time/format.cljs
Normal file
538
resources/public/js/compiled/out/cljs_time/format.cljs
Normal file
|
|
@ -0,0 +1,538 @@
|
|||
(ns cljs-time.format
|
||||
"### Utilities for parsing and unparsing DateTimes as Strings.
|
||||
|
||||
Parsing and printing are controlled by formatters. You can either use one
|
||||
of the built in ISO 8601 and a single RFC 822 formatters or define your own, e.g.:
|
||||
|
||||
(def built-in-formatter (formatters :basic-date-time))
|
||||
(def custom-formatter (formatter \"yyyyMMdd\"))
|
||||
|
||||
To see a list of available built-in formatters and an example of a date-time
|
||||
printed in their format:
|
||||
|
||||
(show-formatters)
|
||||
|
||||
Once you have a formatter, parsing and printing are strait-forward:
|
||||
|
||||
=> (parse custom-formatter \"20100311\")
|
||||
#<DateTime 2010-03-11T00:00:00.000Z>
|
||||
|
||||
=> (unparse custom-formatter (date-time 2010 10 3))
|
||||
\"20101003\"
|
||||
|
||||
By default the parse function always returns a DateTime instance with a UTC
|
||||
time zone, and the unparse function always represents a given DateTime
|
||||
instance in UTC. A formatter can be modified to different timezones, locales,
|
||||
etc with the functions with-zone, with-locale, with-chronology, and
|
||||
with-pivot-year."
|
||||
(:require
|
||||
[cljs-time.internal.core :refer [index-of valid-date? format zero-pad]]
|
||||
[cljs-time.core :as time]
|
||||
[clojure.set :refer [difference]]
|
||||
[clojure.string :as string]
|
||||
[goog.date :as date]
|
||||
[goog.date.duration :as duration]
|
||||
[goog.string :as gstring]
|
||||
[goog.string.format]))
|
||||
|
||||
(def months
|
||||
["January" "February" "March" "April" "May" "June" "July" "August"
|
||||
"September" "October" "November" "December"])
|
||||
|
||||
(def days
|
||||
["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
|
||||
|
||||
(defn abbreviate [n s]
|
||||
(subs s 0 n))
|
||||
|
||||
(def ^{:doc "**Note: not all formatters have been implemented yet.**
|
||||
|
||||
The pattern syntax is mostly compatible with java.text.SimpleDateFormat -
|
||||
time zone names cannot be parsed and a few more symbols are supported. All
|
||||
ASCII letters are reserved as pattern letters, which are defined as follows:
|
||||
|
||||
Symbol Meaning Presentation Examples
|
||||
------ ------- ------------ -------
|
||||
G era text AD
|
||||
C century of era (>=0) number 20
|
||||
Y year of era (>=0) year 1996
|
||||
|
||||
x weekyear year 1996
|
||||
w week of weekyear number 27
|
||||
e day of week number 2
|
||||
E day of week text Tuesday; Tue
|
||||
|
||||
y year year 1996
|
||||
D day of year number 189
|
||||
M month of year month July; Jul; 07
|
||||
d day of month number 10
|
||||
|
||||
a halfday of day text PM
|
||||
K hour of halfday (0~11) number 0
|
||||
h clockhour of halfday (1~12) number 12
|
||||
|
||||
H hour of day (0~23) number 0
|
||||
k clockhour of day (1~24) number 24
|
||||
m minute of hour number 30
|
||||
s second of minute number 55
|
||||
S fraction of second number 978
|
||||
a meridiem text am; pm
|
||||
A meridiem text AM; PM
|
||||
|
||||
z time zone text Pacific Standard Time; PST
|
||||
Z time zone offset/id zone -0800; -08:00; America/Los_Angeles
|
||||
|
||||
' escape for text delimiter
|
||||
'' single quote literal '
|
||||
|
||||
The count of pattern letters determine the format.
|
||||
|
||||
**Text:** If the number of pattern letters is 4 or more, the full form is used;
|
||||
otherwise a short or abbreviated form is used if available.
|
||||
|
||||
**Number:** The minimum number of digits. Shorter numbers are zero-padded to this
|
||||
amount.
|
||||
|
||||
**Year:** Numeric presentation for year and weekyear fields are handled
|
||||
specially. For example, if the count of 'y' is 2, the year will be displayed
|
||||
as the zero-based year of the century, which is two digits.
|
||||
|
||||
**Month:** 3 or over, use text, otherwise use number.
|
||||
|
||||
**Zone:** 'Z' outputs offset without a colon, 'ZZ' outputs the offset with a
|
||||
colon, 'ZZZ' or more outputs the zone id.
|
||||
|
||||
**Zone names:** Time zone names ('z') cannot be parsed.
|
||||
|
||||
Any characters in the pattern that are not in the ranges of ['a'..'z'] and
|
||||
['A'..'Z'] will be treated as quoted text. For instance, characters like ':',
|
||||
'.', ' ', '#' and '?' will appear in the resulting time text even they are
|
||||
not embraced within single quotes."}
|
||||
date-formatters
|
||||
(let [d #(.getDate %)
|
||||
M #(inc (.getMonth %))
|
||||
y #(.getYear %)
|
||||
h #(let [hr (mod (.getHours %) 12)]
|
||||
(if (zero? hr) 12 hr))
|
||||
a #(if (< (.getHours %) 12) "am" "pm")
|
||||
A #(if (< (.getHours %) 12) "AM" "PM")
|
||||
H #(.getHours %)
|
||||
m #(.getMinutes %)
|
||||
s #(.getSeconds %)
|
||||
S #(.getMilliseconds %)
|
||||
Z #(.getTimezoneOffsetString %)
|
||||
doy #(.getDayOfYear %)
|
||||
dow #(.getDay %)]
|
||||
{"d" d
|
||||
"dd" #(zero-pad (d %))
|
||||
"dth" #(let [d (d %)] (str d (case d 1 "st" 2 "nd" 3 "rd" 21 "st" 22 "nd" 23 "rd" 31 "st" "th")))
|
||||
"dow" #(days (dow %))
|
||||
"D" doy
|
||||
"DD" doy
|
||||
"DDD" doy
|
||||
"EEE" #(abbreviate 3 (days (dow %)))
|
||||
"EEEE" #(days (dow %))
|
||||
"M" M
|
||||
"MM" #(zero-pad (M %))
|
||||
"MMM" #(abbreviate 3 (months (dec (M %))))
|
||||
"MMMM" #(months (dec (M %)))
|
||||
"yyyy" y
|
||||
"YYYY" y
|
||||
"yy" #(mod (y %) 100)
|
||||
"YY" #(mod (y %) 100)
|
||||
"xxxx" y
|
||||
"a" a
|
||||
"A" A
|
||||
"h" h
|
||||
"H" H
|
||||
"m" m
|
||||
"s" s
|
||||
"S" S
|
||||
"hh" #(zero-pad (h %))
|
||||
"HH" #(zero-pad (H %))
|
||||
"mm" #(zero-pad (m %))
|
||||
"ss" #(zero-pad (s %))
|
||||
"SSS" #(zero-pad (S %) 3)
|
||||
"Z" Z
|
||||
"ZZ" Z
|
||||
"ww" #(zero-pad (.getWeekNumber %))
|
||||
"e" dow}))
|
||||
|
||||
(defn timezone-adjustment [d timezone-string]
|
||||
(let [[_ sign hh mm] (string/split timezone-string
|
||||
#"Z|(?:([-+])(\d{2})(?::?(\d{2}))?)$")]
|
||||
(when (and sign hh mm)
|
||||
(let [sign (cond (= sign "-") time/plus
|
||||
(= sign "+") time/minus)
|
||||
[hh mm] (map #(js/parseInt % 10) [hh mm])
|
||||
adjusted (-> d
|
||||
(sign (time/hours hh))
|
||||
(sign (time/minutes mm)))]
|
||||
(.setTime d (.getTime adjusted))))
|
||||
d))
|
||||
|
||||
(def date-parsers
|
||||
(let [parse-int #(js/parseInt % 10)
|
||||
assoc-fn (fn [kw] #(assoc %1 kw (parse-int %2)))
|
||||
y (assoc-fn :years)
|
||||
d (assoc-fn :days)
|
||||
M #(assoc %1 :months (dec (parse-int %2)))
|
||||
h #(assoc %1 :hours (mod (parse-int %2) 12))
|
||||
a (fn [{:keys [hours] :as date} x]
|
||||
(if (#{"pm" "p"} (string/lower-case x))
|
||||
(assoc date :hours (let [hours (+ 12 hours)]
|
||||
(if (= hours 24) 0 hours)))
|
||||
date))
|
||||
H (assoc-fn :hours)
|
||||
m (assoc-fn :minutes)
|
||||
s (assoc-fn :seconds)
|
||||
S (assoc-fn :millis)
|
||||
MMM #(let [full (first (filter (fn [m]
|
||||
(re-seq (re-pattern (str "^" %2)) m))
|
||||
months))]
|
||||
(M %1 (str (inc (index-of months full)))))
|
||||
MMMM #(M %1 (str (inc (index-of months %2))))
|
||||
skip (fn [x & args] x)
|
||||
tz #(assoc %1 :time-zone %2)]
|
||||
{"d" ["(\\d{1,2})" d]
|
||||
"dd" ["(\\d{2})" d]
|
||||
"D" ["(\\d{1,3})" d]
|
||||
"DD" ["(\\d{2,3})" d]
|
||||
"DDD" ["(\\d{3})" d]
|
||||
"dth" ["(\\d{1,2})(?:st|nd|rd|th)" d]
|
||||
"M" ["(\\d{1,2})" M]
|
||||
"MM" ["((?:\\d{2})|(?:\\b\\d{1,2}\\b))" M]
|
||||
"y" ["(\\d{1,4})" y]
|
||||
"yy" ["(\\d{2,4})" y]
|
||||
"yyyy" ["(\\d{4})" y]
|
||||
"Y" ["(\\d{1,4})" y]
|
||||
"YY" ["(\\d{2,4})" y]
|
||||
"YYYY" ["(\\d{4})" y]
|
||||
"MMM" [(str \( (string/join \| (map (partial abbreviate 3) months)) \)) MMM]
|
||||
"MMMM" [(str \( (string/join \| months) \)) MMMM]
|
||||
"E" [(str \( (string/join \| (map (partial abbreviate 3) days)) \)) skip]
|
||||
"EEE" [(str \( (string/join \| (map (partial abbreviate 3) days)) \)) skip]
|
||||
"EEEE" [(str \( (string/join \| days) \)) skip]
|
||||
"dow" [(str \( (string/join \| days) \)) skip]
|
||||
"a" ["(am|pm|a|p|AM|PM|A|P)" a]
|
||||
"A" ["(am|pm|a|p|AM|PM|A|P)" a]
|
||||
"m" ["(\\d{1,2})" m]
|
||||
"s" ["(\\d{1,2})" s]
|
||||
"S" ["(\\d{1,2})" S]
|
||||
"h" ["(\\d{1,2})" h]
|
||||
"H" ["(\\d{1,2})" H]
|
||||
"hh" ["(\\d{2})" h]
|
||||
"HH" ["(\\d{2})" H]
|
||||
"mm" ["(\\d{2})" m]
|
||||
"ss" ["(\\d{2})" s]
|
||||
"SSS" ["(\\d{3})" S]
|
||||
"Z" ["((?:(?:\\+|-)\\d{2}:?\\d{2})|Z+)" tz]
|
||||
"ZZ" ["((?:(?:\\+|-)\\d{2}:\\d{2})|Z+)" tz]}))
|
||||
|
||||
(def date-setters
|
||||
{:years #(.setYear %1 %2)
|
||||
:months #(.setMonth %1 %2)
|
||||
:days #(.setDate %1 %2)
|
||||
:hours #(.setHours %1 %2)
|
||||
:minutes #(.setMinutes %1 %2)
|
||||
:seconds #(.setSeconds %1 %2)
|
||||
:millis #(.setMilliseconds %1 %2)
|
||||
:time-zone timezone-adjustment})
|
||||
|
||||
(defn parser-sort-order-pred [parser]
|
||||
(index-of
|
||||
["YYYY" "YY" "Y" "yyyy" "yy" "y" "d" "dd" "D" "DD" "DDD" "dth"
|
||||
"M" "MM" "MMM" "MMMM" "dow" "h" "H" "m" "s" "S" "hh" "HH" "mm" "ss" "a" "A"
|
||||
"SSS" "Z" "ZZ"]
|
||||
parser))
|
||||
|
||||
(def date-format-pattern
|
||||
(re-pattern
|
||||
(str "(" (string/join ")|(" (reverse (sort-by count (keys date-formatters)))) ")")))
|
||||
|
||||
(defn old-string-replace [s match replacement]
|
||||
(.replace s (js/RegExp. (.-source match) "g") replacement))
|
||||
|
||||
(defn date-parse-pattern [formatter]
|
||||
(-> formatter
|
||||
(old-string-replace #"'([^']+)'" "$1")
|
||||
(old-string-replace date-format-pattern #(first (date-parsers %)))
|
||||
re-pattern))
|
||||
|
||||
(defn- parser-fn [fmts]
|
||||
(fn [s]
|
||||
(->> (interleave (nfirst (re-seq (date-parse-pattern fmts) s))
|
||||
(map first (re-seq date-format-pattern fmts)))
|
||||
(partition 2)
|
||||
(sort-by (comp parser-sort-order-pred second)))))
|
||||
|
||||
(defn- formatter-fn [fmts formatters]
|
||||
(fn [date & [formatter-overrides]]
|
||||
(let [a (atom {:c 0})]
|
||||
[(old-string-replace
|
||||
fmts
|
||||
#"'([^']+)'"
|
||||
(fn [x s]
|
||||
(if (and (seq s) (= \' (first x)) (= \' (last x)))
|
||||
(let [{:keys [c]} @a
|
||||
k (str "&&&&" c)]
|
||||
(swap! a assoc-in [:replace k] (constantly s))
|
||||
(swap! a update-in [:c] inc)
|
||||
k)
|
||||
x)))
|
||||
(-> (.-source date-format-pattern)
|
||||
(cond->>
|
||||
(:replace @a)
|
||||
(str "(" (string/join ")|(" (keys (:replace @a))) ")|"))
|
||||
(re-pattern))
|
||||
#(((merge formatters formatter-overrides (:replace @a)) %) date)])))
|
||||
|
||||
(defn formatter
|
||||
([fmts]
|
||||
(formatter fmts time/utc))
|
||||
([fmts dtz]
|
||||
(with-meta
|
||||
{:format-str fmts
|
||||
:formatters date-formatters}
|
||||
{:type ::formatter})))
|
||||
|
||||
(defn formatter-local [fmts]
|
||||
(with-meta
|
||||
{:format-str fmts
|
||||
:formatters (assoc date-formatters
|
||||
"Z" (constantly "")
|
||||
"ZZ" (constantly ""))}
|
||||
{:type ::formatter}))
|
||||
|
||||
(defn not-implemented [sym]
|
||||
#(throw (clj->js {:name :not-implemented
|
||||
:message (format "%s not implemented yet" (name sym))})))
|
||||
|
||||
(defn with-default-year
|
||||
"Return a copy of a formatter that uses the given default year."
|
||||
[f default-year]
|
||||
(assoc f :default-year default-year))
|
||||
|
||||
(def ^{:doc "Map of ISO 8601 and a single RFC 822 formatters that can be used
|
||||
for parsing and, in most cases, printing.
|
||||
|
||||
Note: due to current implementation limitations, timezone information
|
||||
cannot be kept. Although the correct offset will be applied to UTC
|
||||
time if supplied."}
|
||||
formatters
|
||||
{:basic-date (formatter "yyyyMMdd")
|
||||
:basic-date-time (formatter "yyyyMMdd'T'HHmmss.SSSZ")
|
||||
:basic-date-time-no-ms (formatter "yyyyMMdd'T'HHmmssZ")
|
||||
:basic-ordinal-date (formatter "yyyyDDD")
|
||||
:basic-ordinal-date-time (formatter "yyyyDDD'T'HHmmss.SSSZ")
|
||||
:basic-ordinal-date-time-no-ms (formatter "yyyyDDD'T'HHmmssZ")
|
||||
:basic-time (formatter "HHmmss.SSSZ")
|
||||
:basic-time-no-ms (formatter "HHmmssZ")
|
||||
:basic-t-time (formatter "'T'HHmmss.SSSZ")
|
||||
:basic-t-time-no-ms (formatter "'T'HHmmssZ")
|
||||
:basic-week-date (formatter "xxxx'W'wwe")
|
||||
:basic-week-date-time (formatter "xxxx'W'wwe'T'HHmmss.SSSZ")
|
||||
:basic-week-date-time-no-ms (formatter "xxxx'W'wwe'T'HHmmssZ")
|
||||
:date (formatter "yyyy-MM-dd")
|
||||
:date-element-parser (not-implemented 'dateElementParser)
|
||||
:date-hour (formatter "yyyy-MM-dd'T'HH")
|
||||
:date-hour-minute (formatter "yyyy-MM-dd'T'HH:mm")
|
||||
:date-hour-minute-second (formatter "yyyy-MM-dd'T'HH:mm:ss")
|
||||
:date-hour-minute-second-fraction (formatter "yyyy-MM-dd'T'HH:mm:ss.SSS")
|
||||
:date-hour-minute-second-ms (formatter "yyyy-MM-dd'T'HH:mm:ss.SSS")
|
||||
:date-opt-time (not-implemented 'dateOptionalTimeParser)
|
||||
:date-parser (not-implemented 'dateParser)
|
||||
:date-time (formatter "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
|
||||
:date-time-no-ms (formatter "yyyy-MM-dd'T'HH:mm:ssZZ")
|
||||
:date-time-parser (not-implemented 'dateTimeParser)
|
||||
:hour (formatter "HH")
|
||||
:hour-minute (formatter "HH:mm")
|
||||
:hour-minute-second (formatter "HH:mm:ss")
|
||||
:hour-minute-second-fraction (formatter "HH:mm:ss.SSS")
|
||||
:hour-minute-second-ms (formatter "HH:mm:ss.SSS")
|
||||
:local-date-opt-time (not-implemented 'localDateOptionalTimeParser)
|
||||
:local-date (not-implemented 'localDateParser)
|
||||
:local-time (not-implemented 'localTimeParser)
|
||||
:ordinal-date (formatter "yyyy-DDD")
|
||||
:ordinal-date-time (formatter "yyyy-DDD'T'HH:mm:ss.SSSZZ")
|
||||
:ordinal-date-time-no-ms (formatter "yyyy-DDD'T'HH:mm:ssZZ")
|
||||
:time (formatter "HH:mm:ss.SSSZZ")
|
||||
:time-element-parser (not-implemented 'timeElementParser)
|
||||
:time-no-ms (formatter "HH:mm:ssZZ")
|
||||
:time-parser (formatter 'timeParser)
|
||||
:t-time (formatter "'T'HH:mm:ss.SSSZZ")
|
||||
:t-time-no-ms (formatter "'T'HH:mm:ssZZ")
|
||||
:week-date (formatter "xxxx-'W'ww-e")
|
||||
:week-date-time (formatter "xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ")
|
||||
:week-date-time-no-ms (formatter "xxxx-'W'ww-e'T'HH:mm:ssZZ")
|
||||
:weekyear (formatter "xxxx")
|
||||
:weekyear-week (formatter "xxxx-'W'ww")
|
||||
:weekyear-week-day (formatter "xxxx-'W'ww-e")
|
||||
:year (formatter "yyyy")
|
||||
:year-month (formatter "yyyy-MM")
|
||||
:year-month-day (formatter "yyyy-MM-dd")
|
||||
:rfc822 (formatter "EEE, dd MMM yyyy HH:mm:ss Z")
|
||||
:mysql (formatter "yyyy-MM-dd HH:mm:ss")})
|
||||
|
||||
(def ^{:private true} parsers
|
||||
#{:date-element-parser :date-opt-time :date-parser :date-time-parser
|
||||
:local-date-opt-time :local-date :local-time :time-element-parser
|
||||
:time-parser})
|
||||
|
||||
(def ^{:private true} printers
|
||||
(difference (set (keys formatters)) parsers))
|
||||
|
||||
(def part-splitter-regex
|
||||
#"(?:(?!(?:\+|-)\d{2}):(?!\d{2}$))|[^\w:]+|.[TW]|'[^']+'")
|
||||
|
||||
(defprotocol IDateMap
|
||||
(date-map [date]))
|
||||
|
||||
(extend-protocol IDateMap
|
||||
goog.date.Date
|
||||
(date-map [date]
|
||||
{:years 0 :months 0 :days 1})
|
||||
|
||||
goog.date.DateTime
|
||||
(date-map [date]
|
||||
{:years 0 :months 0 :days 1 :hours 0 :minutes 0 :seconds 0 :millis 0})
|
||||
|
||||
goog.date.UtcDateTime
|
||||
(date-map [date]
|
||||
{:years 0 :months 0 :days 1 :hours 0 :minutes 0 :seconds 0 :millis 0
|
||||
:time-zone nil}))
|
||||
|
||||
(defn parse* [constructor {:keys [format-str default-year] :as fmt} s]
|
||||
{:pre [(seq s)]}
|
||||
(let [min-parts (count (string/split s part-splitter-regex))]
|
||||
(let [parse-fn (parser-fn format-str)
|
||||
parse-seq (seq (map (fn [[a b]] [a (second (date-parsers b))])
|
||||
(parse-fn s)))]
|
||||
(if (>= (count parse-seq) min-parts)
|
||||
(let [d (new constructor 0 0 0 0 0 0 0)
|
||||
empty (assoc (date-map d) :years (or default-year 0))
|
||||
setters (select-keys date-setters (keys empty))]
|
||||
(->> parse-seq
|
||||
(reduce (fn [date [part do-parse]] (do-parse date part)) empty)
|
||||
valid-date?
|
||||
(merge-with #(%1 d %2) setters))
|
||||
d)
|
||||
(throw
|
||||
(ex-info "The parser could not match the input string."
|
||||
{:type :parser-no-match}))))))
|
||||
|
||||
(defn parse
|
||||
"Returns a DateTime instance in the UTC time zone obtained by parsing the
|
||||
given string according to the given formatter."
|
||||
([fmt s]
|
||||
(parse* goog.date.UtcDateTime fmt s))
|
||||
([s]
|
||||
(first
|
||||
(for [f (vals formatters)
|
||||
:let [d (try (parse f s) (catch :default _))]
|
||||
:when d] d))))
|
||||
|
||||
(defn parse-local
|
||||
"Returns a local DateTime instance obtained by parsing the
|
||||
given string according to the given formatter."
|
||||
([fmt s]
|
||||
(parse* goog.date.DateTime fmt s))
|
||||
([s]
|
||||
(first
|
||||
(for [f (vals formatters)
|
||||
:let [d (try (parse-local f s) (catch js/Error _ nil))]
|
||||
:when d] d))))
|
||||
|
||||
(defn parse-local-date
|
||||
"Returns a local Date instance obtained by parsing the
|
||||
given string according to the given formatter."
|
||||
([fmt s]
|
||||
(parse* goog.date.Date fmt s))
|
||||
([s]
|
||||
(first
|
||||
(for [f (vals formatters)
|
||||
:let [d (try (parse-local-date f s) (catch js/Error _ nil))]
|
||||
:when d] d))))
|
||||
|
||||
(defn unparse
|
||||
"Returns a string representing the given DateTime instance in UTC and in the
|
||||
form determined by the given formatter."
|
||||
[{:keys [format-str formatters]} dt]
|
||||
{:pre [(not (nil? dt)) (instance? goog.date.DateTime dt)]}
|
||||
(apply old-string-replace ((formatter-fn format-str formatters) dt)))
|
||||
|
||||
(defn unparse-local
|
||||
"Returns a string representing the given local DateTime instance in the
|
||||
form determined by the given formatter."
|
||||
[{:keys [format-str formatters] :as fmt} dt]
|
||||
{:pre [(not (nil? dt)) (instance? goog.date.DateTime dt)]}
|
||||
(apply old-string-replace
|
||||
((formatter-fn format-str formatters) dt (assoc date-formatters
|
||||
"Z" (constantly "")
|
||||
"ZZ" (constantly "")))))
|
||||
|
||||
(defn unparse-local-date
|
||||
"Returns a string representing the given local Date instance in the form
|
||||
determined by the given formatter."
|
||||
[{:keys [format-str formatters] :as fmt} dt]
|
||||
{:pre [(not (nil? dt)) (instance? goog.date.Date dt)]}
|
||||
(apply old-string-replace
|
||||
((formatter-fn format-str formatters) dt (assoc date-formatters
|
||||
"Z" (constantly "")
|
||||
"ZZ" (constantly "")))))
|
||||
|
||||
(defn show-formatters
|
||||
"Shows how a given DateTime, or by default the current time, would be
|
||||
formatted with each of the available printing formatters."
|
||||
([] (show-formatters (time/now)))
|
||||
([dt]
|
||||
(doseq [p (sort printers)]
|
||||
(let [fmt (formatters p)]
|
||||
(print (format "%-40s%s\n" p (unparse fmt dt)))))))
|
||||
|
||||
(defprotocol Mappable
|
||||
(instant->map [instant] "Returns a map representation of the given instant.
|
||||
It will contain the following keys: :years, :months,
|
||||
:days, :hours, :minutes and :seconds."))
|
||||
|
||||
(defn unparse-duration
|
||||
"Accepts a Period or Interval and outputs an absolute duration time
|
||||
in form of \"1 day\", \"2 hours\", \"20 minutes\", \"2 days 1 hour
|
||||
15 minutes\" etc."
|
||||
[duration]
|
||||
(-> duration time/in-millis duration/format))
|
||||
|
||||
(defn- to-map [years months days hours minutes seconds millis]
|
||||
{:years years
|
||||
:months months
|
||||
:days days
|
||||
:hours hours
|
||||
:minutes minutes
|
||||
:seconds seconds
|
||||
:millis millis})
|
||||
|
||||
(extend-protocol Mappable
|
||||
goog.date.UtcDateTime
|
||||
(instant->map [dt]
|
||||
(to-map
|
||||
(.getYear dt)
|
||||
(inc (.getMonth dt))
|
||||
(.getDate dt)
|
||||
(.getHours dt)
|
||||
(.getMinutes dt)
|
||||
(.getSeconds dt)
|
||||
(.getMilliseconds dt)))
|
||||
|
||||
cljs-time.core.Period
|
||||
(instant->map [m]
|
||||
(time/->period m))
|
||||
|
||||
cljs-time.core.Interval
|
||||
(instant->map [m]
|
||||
(time/->period m))
|
||||
|
||||
cljs.core/PersistentArrayMap
|
||||
(instant->map [m]
|
||||
(case (:type (meta m))
|
||||
:cljs-time.core/period m
|
||||
:cljs-time.core/interval (time/->period m))))
|
||||
File diff suppressed because one or more lines are too long
1223
resources/public/js/compiled/out/cljs_time/format.js
Normal file
1223
resources/public/js/compiled/out/cljs_time/format.js
Normal file
File diff suppressed because one or more lines are too long
1
resources/public/js/compiled/out/cljs_time/format.js.map
Normal file
1
resources/public/js/compiled/out/cljs_time/format.js.map
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,73 @@
|
|||
(ns cljs-time.internal.core
|
||||
(:refer-clojure :exclude [=])
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[goog.string :as gstring]
|
||||
[goog.string.format]))
|
||||
|
||||
(defn = [& args]
|
||||
(cond (every? #(instance? goog.date.Date %) args)
|
||||
(apply cljs.core/= (map #(.getTime %) args))
|
||||
:default (apply cljs.core/= args)))
|
||||
|
||||
(defn leap-year? [y]
|
||||
(cond (zero? (mod y 400)) true
|
||||
(zero? (mod y 100)) false
|
||||
(zero? (mod y 4)) true
|
||||
:else false))
|
||||
|
||||
(def days-in-month [31 28 31 30 31 30 31 31 30 31 30 31])
|
||||
|
||||
(defn year-corrected-dim [year month]
|
||||
(cond-> (days-in-month (if (= month 1) 11 (dec month)))
|
||||
(and (leap-year? year) (= month 2)) inc))
|
||||
|
||||
(defn valid-date?
|
||||
[{:keys [years months days hours minutes seconds millis] :as d}]
|
||||
(let [months (inc months)]
|
||||
(if (and years
|
||||
(<= 1 months 12)
|
||||
(<= 1 days (year-corrected-dim years months))
|
||||
(<= 0 hours 23)
|
||||
(<= 0 minutes 59)
|
||||
(<= 0 seconds 60)
|
||||
(<= 0 millis 999))
|
||||
d
|
||||
(throw (ex-info "Date is not valid" {:type :invalid-date :date d})))))
|
||||
|
||||
(defn index-of [coll x]
|
||||
(first (keep-indexed #(when (= %2 x) %1) coll)))
|
||||
|
||||
(defn format
|
||||
"Formats a string using goog.string.format."
|
||||
[fmt & args]
|
||||
(let [args (map (fn [x]
|
||||
(if (or (keyword? x) (symbol? x))
|
||||
(str x)
|
||||
x))
|
||||
args)]
|
||||
(apply gstring/format fmt args)))
|
||||
|
||||
(defn zero-pad
|
||||
"Remove the need to pull in gstring/format code in advanced compilation"
|
||||
([n] (if (<= 0 n 9) (str "0" n) (str n)))
|
||||
([n zeros]
|
||||
; No need to handle negative numbers
|
||||
(if (> 1 zeros)
|
||||
(str n)
|
||||
(str (string/join (take (- zeros (count (str n))) (repeat "0")))
|
||||
n))))
|
||||
|
||||
(defn multiplied-by [period scalar]
|
||||
(letfn [(scale-fn [field]
|
||||
(when field
|
||||
(* field scalar)))]
|
||||
(-> period
|
||||
(update-in [:millis] scale-fn)
|
||||
(update-in [:seconds] scale-fn)
|
||||
(update-in [:minutes] scale-fn)
|
||||
(update-in [:hours] scale-fn)
|
||||
(update-in [:days] scale-fn)
|
||||
(update-in [:weeks] scale-fn)
|
||||
(update-in [:months] scale-fn)
|
||||
(update-in [:years] scale-fn))))
|
||||
File diff suppressed because one or more lines are too long
216
resources/public/js/compiled/out/cljs_time/internal/core.js
Normal file
216
resources/public/js/compiled/out/cljs_time/internal/core.js
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
// Compiled by ClojureScript 1.9.229 {}
|
||||
goog.provide('cljs_time.internal.core');
|
||||
goog.require('cljs.core');
|
||||
goog.require('clojure.string');
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.string.format');
|
||||
cljs_time.internal.core._EQ_ = (function cljs_time$internal$core$_EQ_(var_args){
|
||||
var args__26212__auto__ = [];
|
||||
var len__26205__auto___31798 = arguments.length;
|
||||
var i__26206__auto___31799 = (0);
|
||||
while(true){
|
||||
if((i__26206__auto___31799 < len__26205__auto___31798)){
|
||||
args__26212__auto__.push((arguments[i__26206__auto___31799]));
|
||||
|
||||
var G__31800 = (i__26206__auto___31799 + (1));
|
||||
i__26206__auto___31799 = G__31800;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var argseq__26213__auto__ = ((((0) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((0)),(0),null)):null);
|
||||
return cljs_time.internal.core._EQ_.cljs$core$IFn$_invoke$arity$variadic(argseq__26213__auto__);
|
||||
});
|
||||
|
||||
cljs_time.internal.core._EQ_.cljs$core$IFn$_invoke$arity$variadic = (function (args){
|
||||
if(cljs.core.every_QMARK_.call(null,(function (p1__31795_SHARP_){
|
||||
return (p1__31795_SHARP_ instanceof goog.date.Date);
|
||||
}),args)){
|
||||
return cljs.core.apply.call(null,cljs.core._EQ_,cljs.core.map.call(null,(function (p1__31796_SHARP_){
|
||||
return p1__31796_SHARP_.getTime();
|
||||
}),args));
|
||||
} else {
|
||||
return cljs.core.apply.call(null,cljs.core._EQ_,args);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
cljs_time.internal.core._EQ_.cljs$lang$maxFixedArity = (0);
|
||||
|
||||
cljs_time.internal.core._EQ_.cljs$lang$applyTo = (function (seq31797){
|
||||
return cljs_time.internal.core._EQ_.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq31797));
|
||||
});
|
||||
|
||||
cljs_time.internal.core.leap_year_QMARK_ = (function cljs_time$internal$core$leap_year_QMARK_(y){
|
||||
if((cljs.core.mod.call(null,y,(400)) === (0))){
|
||||
return true;
|
||||
} else {
|
||||
if((cljs.core.mod.call(null,y,(100)) === (0))){
|
||||
return false;
|
||||
} else {
|
||||
if((cljs.core.mod.call(null,y,(4)) === (0))){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
cljs_time.internal.core.days_in_month = new cljs.core.PersistentVector(null, 12, 5, cljs.core.PersistentVector.EMPTY_NODE, [(31),(28),(31),(30),(31),(30),(31),(31),(30),(31),(30),(31)], null);
|
||||
cljs_time.internal.core.year_corrected_dim = (function cljs_time$internal$core$year_corrected_dim(year,month){
|
||||
var G__31802 = cljs_time.internal.core.days_in_month.call(null,(cljs.core.truth_(cljs_time.internal.core._EQ_.call(null,month,(1)))?(11):(month - (1))));
|
||||
if(cljs.core.truth_((function (){var and__25118__auto__ = cljs_time.internal.core.leap_year_QMARK_.call(null,year);
|
||||
if(cljs.core.truth_(and__25118__auto__)){
|
||||
return cljs_time.internal.core._EQ_.call(null,month,(2));
|
||||
} else {
|
||||
return and__25118__auto__;
|
||||
}
|
||||
})())){
|
||||
return (G__31802 + (1));
|
||||
} else {
|
||||
return G__31802;
|
||||
}
|
||||
});
|
||||
cljs_time.internal.core.valid_date_QMARK_ = (function cljs_time$internal$core$valid_date_QMARK_(p__31803){
|
||||
var map__31806 = p__31803;
|
||||
var map__31806__$1 = ((((!((map__31806 == null)))?((((map__31806.cljs$lang$protocol_mask$partition0$ & (64))) || (map__31806.cljs$core$ISeq$))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__31806):map__31806);
|
||||
var d = map__31806__$1;
|
||||
var years = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"years","years",-1298579689));
|
||||
var months = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"months","months",-45571637));
|
||||
var days = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"days","days",-1394072564));
|
||||
var hours = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"hours","hours",58380855));
|
||||
var minutes = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"minutes","minutes",1319166394));
|
||||
var seconds = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"seconds","seconds",-445266194));
|
||||
var millis = cljs.core.get.call(null,map__31806__$1,new cljs.core.Keyword(null,"millis","millis",-1338288387));
|
||||
var months__$1 = (months + (1));
|
||||
if(cljs.core.truth_((function (){var and__25118__auto__ = years;
|
||||
if(cljs.core.truth_(and__25118__auto__)){
|
||||
return ((((1) <= months__$1)) && ((months__$1 <= (12)))) && ((((1) <= days)) && ((days <= cljs_time.internal.core.year_corrected_dim.call(null,years,months__$1)))) && ((((0) <= hours)) && ((hours <= (23)))) && ((((0) <= minutes)) && ((minutes <= (59)))) && ((((0) <= seconds)) && ((seconds <= (60)))) && ((((0) <= millis)) && ((millis <= (999))));
|
||||
} else {
|
||||
return and__25118__auto__;
|
||||
}
|
||||
})())){
|
||||
return d;
|
||||
} else {
|
||||
throw cljs.core.ex_info.call(null,"Date is not valid",new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"type","type",1174270348),new cljs.core.Keyword(null,"invalid-date","invalid-date",2030506573),new cljs.core.Keyword(null,"date","date",-1463434462),d], null));
|
||||
}
|
||||
});
|
||||
cljs_time.internal.core.index_of = (function cljs_time$internal$core$index_of(coll,x){
|
||||
return cljs.core.first.call(null,cljs.core.keep_indexed.call(null,(function (p1__31809_SHARP_,p2__31808_SHARP_){
|
||||
if(cljs.core.truth_(cljs_time.internal.core._EQ_.call(null,p2__31808_SHARP_,x))){
|
||||
return p1__31809_SHARP_;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}),coll));
|
||||
});
|
||||
/**
|
||||
* Formats a string using goog.string.format.
|
||||
*/
|
||||
cljs_time.internal.core.format = (function cljs_time$internal$core$format(var_args){
|
||||
var args__26212__auto__ = [];
|
||||
var len__26205__auto___31812 = arguments.length;
|
||||
var i__26206__auto___31813 = (0);
|
||||
while(true){
|
||||
if((i__26206__auto___31813 < len__26205__auto___31812)){
|
||||
args__26212__auto__.push((arguments[i__26206__auto___31813]));
|
||||
|
||||
var G__31814 = (i__26206__auto___31813 + (1));
|
||||
i__26206__auto___31813 = G__31814;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var argseq__26213__auto__ = ((((1) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((1)),(0),null)):null);
|
||||
return cljs_time.internal.core.format.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__26213__auto__);
|
||||
});
|
||||
|
||||
cljs_time.internal.core.format.cljs$core$IFn$_invoke$arity$variadic = (function (fmt,args){
|
||||
var args__$1 = cljs.core.map.call(null,(function (x){
|
||||
if(((x instanceof cljs.core.Keyword)) || ((x instanceof cljs.core.Symbol))){
|
||||
return [cljs.core.str(x)].join('');
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}),args);
|
||||
return cljs.core.apply.call(null,goog.string.format,fmt,args__$1);
|
||||
});
|
||||
|
||||
cljs_time.internal.core.format.cljs$lang$maxFixedArity = (1);
|
||||
|
||||
cljs_time.internal.core.format.cljs$lang$applyTo = (function (seq31810){
|
||||
var G__31811 = cljs.core.first.call(null,seq31810);
|
||||
var seq31810__$1 = cljs.core.next.call(null,seq31810);
|
||||
return cljs_time.internal.core.format.cljs$core$IFn$_invoke$arity$variadic(G__31811,seq31810__$1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove the need to pull in gstring/format code in advanced compilation
|
||||
*/
|
||||
cljs_time.internal.core.zero_pad = (function cljs_time$internal$core$zero_pad(var_args){
|
||||
var args31815 = [];
|
||||
var len__26205__auto___31818 = arguments.length;
|
||||
var i__26206__auto___31819 = (0);
|
||||
while(true){
|
||||
if((i__26206__auto___31819 < len__26205__auto___31818)){
|
||||
args31815.push((arguments[i__26206__auto___31819]));
|
||||
|
||||
var G__31820 = (i__26206__auto___31819 + (1));
|
||||
i__26206__auto___31819 = G__31820;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var G__31817 = args31815.length;
|
||||
switch (G__31817) {
|
||||
case 1:
|
||||
return cljs_time.internal.core.zero_pad.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
|
||||
|
||||
break;
|
||||
case 2:
|
||||
return cljs_time.internal.core.zero_pad.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
|
||||
|
||||
break;
|
||||
default:
|
||||
throw (new Error([cljs.core.str("Invalid arity: "),cljs.core.str(args31815.length)].join('')));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
cljs_time.internal.core.zero_pad.cljs$core$IFn$_invoke$arity$1 = (function (n){
|
||||
if((((0) <= n)) && ((n <= (9)))){
|
||||
return [cljs.core.str("0"),cljs.core.str(n)].join('');
|
||||
} else {
|
||||
return [cljs.core.str(n)].join('');
|
||||
}
|
||||
});
|
||||
|
||||
cljs_time.internal.core.zero_pad.cljs$core$IFn$_invoke$arity$2 = (function (n,zeros){
|
||||
if(((1) > zeros)){
|
||||
return [cljs.core.str(n)].join('');
|
||||
} else {
|
||||
return [cljs.core.str(clojure.string.join.call(null,cljs.core.take.call(null,(zeros - cljs.core.count.call(null,[cljs.core.str(n)].join(''))),cljs.core.repeat.call(null,"0")))),cljs.core.str(n)].join('');
|
||||
}
|
||||
});
|
||||
|
||||
cljs_time.internal.core.zero_pad.cljs$lang$maxFixedArity = 2;
|
||||
|
||||
cljs_time.internal.core.multiplied_by = (function cljs_time$internal$core$multiplied_by(period,scalar){
|
||||
var scale_fn = (function cljs_time$internal$core$multiplied_by_$_scale_fn(field){
|
||||
if(cljs.core.truth_(field)){
|
||||
return (field * scalar);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return cljs.core.update_in.call(null,cljs.core.update_in.call(null,cljs.core.update_in.call(null,cljs.core.update_in.call(null,cljs.core.update_in.call(null,cljs.core.update_in.call(null,cljs.core.update_in.call(null,cljs.core.update_in.call(null,period,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"millis","millis",-1338288387)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"seconds","seconds",-445266194)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"minutes","minutes",1319166394)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"hours","hours",58380855)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"days","days",-1394072564)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"weeks","weeks",1844596125)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"months","months",-45571637)], null),scale_fn),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"years","years",-1298579689)], null),scale_fn);
|
||||
});
|
||||
|
||||
//# sourceMappingURL=core.js.map?rel=1603199194749
|
||||
File diff suppressed because one or more lines are too long
75
resources/public/js/compiled/out/cljs_time/predicates.cljs
Normal file
75
resources/public/js/compiled/out/cljs_time/predicates.cljs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
(ns cljs-time.predicates
|
||||
"### Predicate functions to ask basic questions about a date.
|
||||
|
||||
Was it Monday?
|
||||
(monday? (clj-time.core/date-time 1999 9 9))
|
||||
|
||||
Is it January?
|
||||
(january? (clj-time.core/date-time 2011 1 1))"
|
||||
(:require [cljs-time.core :as time]))
|
||||
|
||||
;; days of the week
|
||||
(defn monday? [date-time]
|
||||
(= (time/day-of-week date-time) 1))
|
||||
|
||||
(defn tuesday? [date-time]
|
||||
(= (time/day-of-week date-time) 2))
|
||||
|
||||
(defn wednesday? [date-time]
|
||||
(= (time/day-of-week date-time) 3))
|
||||
|
||||
(defn thursday? [date-time]
|
||||
(= (time/day-of-week date-time) 4))
|
||||
|
||||
(defn friday? [date-time]
|
||||
(= (time/day-of-week date-time) 5))
|
||||
|
||||
(defn saturday? [date-time]
|
||||
(= (time/day-of-week date-time) 6))
|
||||
|
||||
(defn sunday? [date-time]
|
||||
(= (time/day-of-week date-time) 7))
|
||||
|
||||
;; weekend / weekday checks
|
||||
(defn weekend? [date-time]
|
||||
(or (saturday? date-time) (sunday? date-time)))
|
||||
|
||||
(defn weekday? [date-time]
|
||||
(not (weekend? date-time)))
|
||||
|
||||
;; months of the year
|
||||
(defn january? [date-time]
|
||||
(= (time/month date-time) 1))
|
||||
|
||||
(defn february? [date-time]
|
||||
(= (time/month date-time) 2))
|
||||
|
||||
(defn march? [date-time]
|
||||
(= (time/month date-time) 3))
|
||||
|
||||
(defn april? [date-time]
|
||||
(= (time/month date-time) 4))
|
||||
|
||||
(defn may? [date-time]
|
||||
(= (time/month date-time) 5))
|
||||
|
||||
(defn june? [date-time]
|
||||
(= (time/month date-time) 6))
|
||||
|
||||
(defn july? [date-time]
|
||||
(= (time/month date-time) 7))
|
||||
|
||||
(defn august? [date-time]
|
||||
(= (time/month date-time) 8))
|
||||
|
||||
(defn september? [date-time]
|
||||
(= (time/month date-time) 9))
|
||||
|
||||
(defn october? [date-time]
|
||||
(= (time/month date-time) 10))
|
||||
|
||||
(defn november? [date-time]
|
||||
(= (time/month date-time) 11))
|
||||
|
||||
(defn december? [date-time]
|
||||
(= (time/month date-time) 12))
|
||||
File diff suppressed because one or more lines are too long
74
resources/public/js/compiled/out/cljs_time/predicates.js
Normal file
74
resources/public/js/compiled/out/cljs_time/predicates.js
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// Compiled by ClojureScript 1.9.229 {}
|
||||
goog.provide('cljs_time.predicates');
|
||||
goog.require('cljs.core');
|
||||
goog.require('cljs_time.core');
|
||||
cljs_time.predicates.monday_QMARK_ = (function cljs_time$predicates$monday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(1));
|
||||
});
|
||||
cljs_time.predicates.tuesday_QMARK_ = (function cljs_time$predicates$tuesday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(2));
|
||||
});
|
||||
cljs_time.predicates.wednesday_QMARK_ = (function cljs_time$predicates$wednesday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(3));
|
||||
});
|
||||
cljs_time.predicates.thursday_QMARK_ = (function cljs_time$predicates$thursday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(4));
|
||||
});
|
||||
cljs_time.predicates.friday_QMARK_ = (function cljs_time$predicates$friday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(5));
|
||||
});
|
||||
cljs_time.predicates.saturday_QMARK_ = (function cljs_time$predicates$saturday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(6));
|
||||
});
|
||||
cljs_time.predicates.sunday_QMARK_ = (function cljs_time$predicates$sunday_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.day_of_week.call(null,date_time),(7));
|
||||
});
|
||||
cljs_time.predicates.weekend_QMARK_ = (function cljs_time$predicates$weekend_QMARK_(date_time){
|
||||
var or__25130__auto__ = cljs_time.predicates.saturday_QMARK_.call(null,date_time);
|
||||
if(cljs.core.truth_(or__25130__auto__)){
|
||||
return or__25130__auto__;
|
||||
} else {
|
||||
return cljs_time.predicates.sunday_QMARK_.call(null,date_time);
|
||||
}
|
||||
});
|
||||
cljs_time.predicates.weekday_QMARK_ = (function cljs_time$predicates$weekday_QMARK_(date_time){
|
||||
return cljs.core.not.call(null,cljs_time.predicates.weekend_QMARK_.call(null,date_time));
|
||||
});
|
||||
cljs_time.predicates.january_QMARK_ = (function cljs_time$predicates$january_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(1));
|
||||
});
|
||||
cljs_time.predicates.february_QMARK_ = (function cljs_time$predicates$february_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(2));
|
||||
});
|
||||
cljs_time.predicates.march_QMARK_ = (function cljs_time$predicates$march_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(3));
|
||||
});
|
||||
cljs_time.predicates.april_QMARK_ = (function cljs_time$predicates$april_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(4));
|
||||
});
|
||||
cljs_time.predicates.may_QMARK_ = (function cljs_time$predicates$may_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(5));
|
||||
});
|
||||
cljs_time.predicates.june_QMARK_ = (function cljs_time$predicates$june_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(6));
|
||||
});
|
||||
cljs_time.predicates.july_QMARK_ = (function cljs_time$predicates$july_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(7));
|
||||
});
|
||||
cljs_time.predicates.august_QMARK_ = (function cljs_time$predicates$august_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(8));
|
||||
});
|
||||
cljs_time.predicates.september_QMARK_ = (function cljs_time$predicates$september_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(9));
|
||||
});
|
||||
cljs_time.predicates.october_QMARK_ = (function cljs_time$predicates$october_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(10));
|
||||
});
|
||||
cljs_time.predicates.november_QMARK_ = (function cljs_time$predicates$november_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(11));
|
||||
});
|
||||
cljs_time.predicates.december_QMARK_ = (function cljs_time$predicates$december_QMARK_(date_time){
|
||||
return cljs.core._EQ_.call(null,cljs_time.core.month.call(null,date_time),(12));
|
||||
});
|
||||
|
||||
//# sourceMappingURL=predicates.js.map?rel=1603199196017
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"\/Users\/simon\/workspace\/swinging-needle-meter\/docs\/js\/compiled\/out\/cljs_time\/predicates.js","sources":["predicates.cljs?rel=1603199196018"],"lineCount":74,"mappings":";AAAA;;;AAWA,qCAAA,rCAAMA,kFAASC;AAAf,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAEvB,sCAAA,tCAAMG,oFAAUH;AAAhB,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAEvB,wCAAA,xCAAMI,wFAAYJ;AAAlB,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAEvB,uCAAA,vCAAMK,sFAAWL;AAAjB,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAEvB,qCAAA,rCAAMM,kFAASN;AAAf,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAEvB,uCAAA,vCAAMO,sFAAWP;AAAjB,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAEvB,qCAAA,rCAAMQ,kFAASR;AAAf,AACE,gFAAA,zEAACC,yBAAE,AAACC,qCAAiBF;;AAGvB,sCAAA,tCAAMS,oFAAUT;AAAhB,AACE,IAAAU,oBAAI,AAACH,+CAAUP;AAAf,AAAA,oBAAAU;AAAAA;;AAA0B,OAACF,6CAAQR;;;AAErC,sCAAA,tCAAMW,oFAAUX;AAAhB,AACE,OAACY,wBAAI,AAACH,8CAAST;;AAGjB,sCAAA,tCAAMa,oFAAUb;AAAhB,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,uCAAA,vCAAMe,sFAAWf;AAAjB,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,oCAAA,pCAAMgB,gFAAQhB;AAAd,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,oCAAA,pCAAMiB,gFAAQjB;AAAd,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,kCAAA,lCAAMkB,4EAAMlB;AAAZ,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,mCAAA,nCAAMmB,8EAAOnB;AAAb,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,mCAAA,nCAAMoB,8EAAOpB;AAAb,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,qCAAA,rCAAMqB,kFAASrB;AAAf,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,wCAAA,xCAAMsB,wFAAYtB;AAAlB,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,sCAAA,tCAAMuB,oFAAUvB;AAAhB,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,uCAAA,vCAAMwB,sFAAWxB;AAAjB,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd;;AAEjB,uCAAA,vCAAMyB,sFAAWzB;AAAjB,AACE,0EAAA,nEAACC,yBAAE,AAACa,+BAAWd","names":["cljs-time.predicates\/monday?","date-time","cljs.core\/=","cljs-time.core\/day-of-week","cljs-time.predicates\/tuesday?","cljs-time.predicates\/wednesday?","cljs-time.predicates\/thursday?","cljs-time.predicates\/friday?","cljs-time.predicates\/saturday?","cljs-time.predicates\/sunday?","cljs-time.predicates\/weekend?","or__25130__auto__","cljs-time.predicates\/weekday?","cljs.core\/not","cljs-time.predicates\/january?","cljs-time.core\/month","cljs-time.predicates\/february?","cljs-time.predicates\/march?","cljs-time.predicates\/april?","cljs-time.predicates\/may?","cljs-time.predicates\/june?","cljs-time.predicates\/july?","cljs-time.predicates\/august?","cljs-time.predicates\/september?","cljs-time.predicates\/october?","cljs-time.predicates\/november?","cljs-time.predicates\/december?"]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue