-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathextend.cljs
44 lines (39 loc) · 1.3 KB
/
extend.cljs
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
(ns cljs-time.extend
"### Optional namespace to extend goog.date.* DateTime types
Equality of goog.date.* DateTime types works differently to
clj-time/Joda's equality. Optionally require this namespace
to extend cljs.core/IEquiv protocol for:
* goog.date.Date
* goog.date.DateTime
* goog.date.UtcDateTime"
(:require
[goog.date.Date]
[goog.date.DateTime]
[goog.date.UtcDateTime]))
(extend-type goog.date.Date
IEquiv
(-equiv [o other]
(and (instance? goog.date.Date other)
(identical? (.getTime o) (.getTime other))
(identical? (.getTimezoneOffset o) (.getTimezoneOffset other))))
IComparable
(-compare [o other]
(- (.getTime o) (.getTime other))))
(extend-type goog.date.DateTime
IEquiv
(-equiv [o other]
(and (instance? goog.date.Date other)
(identical? (.getTime o) (.getTime other))
(identical? (.getTimezoneOffset o) (.getTimezoneOffset other))))
IComparable
(-compare [o other]
(- (.getTime o) (.getTime other))))
(extend-type goog.date.UtcDateTime
IEquiv
(-equiv [o other]
(and (instance? goog.date.Date other)
(identical? (.getTime o) (.getTime other))
(identical? (.getTimezoneOffset o) (.getTimezoneOffset other))))
IComparable
(-compare [o other]
(- (.getTime o) (.getTime other))))