forked from dm3/clojure.java-time
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsugar.clj
More file actions
37 lines (33 loc) · 1.14 KB
/
sugar.clj
File metadata and controls
37 lines (33 loc) · 1.14 KB
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
(ns java-time.sugar
(:require [clojure.string :as str]
[java-time.core :as jt.c]
[java-time.util :as jt.u]))
(defmacro gen-sugar-fns
[]
(conj (map (fn [[day-name day-number]]
`(defn ~(symbol (str day-name '?))
~(str "Returns true if the given time entity with the\n"
" `day-of-week` property falls on a " (str/capitalize day-name) ", otherwise false.")
{:arglists '[[~'i]]}
[o#]
(if-let [p# (jt.c/property o# :day-of-week)]
(= (jt.c/value p#) ~day-number)
(throw (java.time.DateTimeException. (str "Day of week unsupported for: " (type o#)))))))
[['monday 1]
['tuesday 2]
['wednesday 3]
['thursday 4]
['friday 5]
['saturday 6]
['sunday 7]])
'do))
(gen-sugar-fns)
(defn weekend?
"Returns true if argument is [[saturday?]] or [[sunday?]],
otherwise false."
[dt]
(or (saturday? dt) (sunday? dt)))
(defn weekday?
"Complement of [[weekend?]]."
[dt]
(not (weekend? dt)))