Skip to content

Commit 571cbff

Browse files
tonskyswannodette
authored andcommitted
CLJS-1096: Update js/Date -equiv and -compare semantics based on Date.valueOf() value
1 parent 8cf3a53 commit 571cbff

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/cljs/cljs/core.cljs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,11 @@
957957
IEquiv
958958
(-equiv [o other]
959959
(and (instance? js/Date other)
960-
(identical? (.toString o) (.toString other)))))
960+
(== (.valueOf o) (.valueOf other))))
961+
962+
IComparable
963+
(-compare [this other]
964+
(garray/defaultCompare (.valueOf this) (.valueOf other))))
961965

962966
(extend-type number
963967
IEquiv

test/cljs/cljs/core_test.cljs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,13 @@
16731673
(is (= -1 (compare (subvec [1 2 3] 1) (subvec [1 2 4] 1))))
16741674
(is (= 0 (compare (subvec [1 2 3] 1) (subvec [1 2 3] 1))))
16751675
(is (= 1 (compare (subvec [1 2 4] 1) (subvec [1 2 3] 1)))))
1676+
1677+
(is (= 0 (compare (js/Date. 2015 2 8 19 13 00 999)
1678+
(js/Date. 2015 2 8 19 13 00 999))))
1679+
(is (= -1 (compare (js/Date. 2015 2 8 19 12 00 999)
1680+
(js/Date. 2015 2 8 19 13 00 999))))
1681+
(is (= 1 (compare (js/Date. 2015 2 8 19 14 00 999)
1682+
(js/Date. 2015 2 8 19 13 00 999))))
16761683
)
16771684

16781685
(deftest test-dot

0 commit comments

Comments
 (0)