/
date.cljc
89 lines (76 loc) · 2.6 KB
/
date.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(ns axel-f.excel.date
(:require #?(:clj [java-time :as jt])
[axel-f.excel.coerce :as coerce]))
(defn NOW*
"Returns the current date and time as a date value."
[]
#?(:clj (jt/local-date-time)
:cljs (js/Date.)))
(def NOW #'NOW*)
(defn TODAY*
"Returns the current date as a date value."
[]
#?(:clj (jt/local-date)
:cljs (let [n (js/Date.)]
(js/Date. (js/Date.UTC (.getUTCFullYear n)
(.getUTCMonth n)
(.getUTCDate n))))))
(def TODAY #'TODAY*)
(defn DATE*
"Converts a year, month, and day into a date."
[^{:doc "The year component of the date."} year
^{:doc "The month component of the date."} month
^{:doc "The day component of the date."} day]
#?(:clj (jt/local-date (coerce/excel-number year)
(coerce/excel-number month)
(coerce/excel-number day))
:cljs (js/Date. (js/Date.UTC (coerce/excel-number year)
(dec (coerce/excel-number month))
(coerce/excel-number day)))))
(def DATE #'DATE*)
(defn DAY*
"Returns the day of the month that a specific date falls on, in numeric format."
[^{:doc "The date from which to extract the day. Must be a reference containing a date, or a function returning a date type.
"} date]
#?(:clj (jt/as date :day-of-month)
:cljs (.getUTCDate date)))
(def DAY #'DAY*)
(defn MONTH*
"Returns the month of the year a specific date falls in, in numeric format."
[^{:doc "The date from which to extract the month. Must be a reference containing a date, or a function returning a date type"} date]
#?(:clj (jt/as date :month-of-year)
:cljs (inc (.getUTCMonth date))))
(def MONTH #'MONTH*)
(defn YEAR*
"Returns the year specified by a given date."
[^{:doc "The date from which to calculate the year. Must be a reference containing a date, or a function returning a date type."} date]
#?(:clj (jt/as date :year)
:cljs (.getUTCFullYear date)))
(def YEAR #'YEAR*)
(def env
{"YEAR" YEAR
"MONTH" MONTH
"NOW" NOW
;; "NETWORKDAYS" NETWORKDAYS
;; "DAYS" DAYS
"DATE" DATE
;; "DAYS360" DAYS360
;; "YEARFRAC" YEARFRAC
;; "WEEKDAY" WEEKDAY
;; "TIME" TIME
;; "WORKDAY" WORKDAY
;; "EDATE" EDATE
;; "WEEKNUM" WEEKNUM
;; "EOMONTH" EOMONTH
;; "ISOWEEKNUM" ISOWEEKNUM
"DAY" DAY
;; "MINUTE" MINUTE
;; "WORKDAY.INTL" WORKDAY.INTL
;; "NETWORKDAYS.INTL" NETWORKDAYS.INTL
;; "DATEDIF" DATEDIF
;; "HOUR" HOUR
;; "TIMEVALUE" TIMEVALUE
;; "DATEVALUE" DATEVALUE
;; "SECOND" SECOND
"TODAY" TODAY
})