Skip to content

Commit 133b110

Browse files
committed
1 parent 9338051 commit 133b110

File tree

5 files changed

+216
-178
lines changed

5 files changed

+216
-178
lines changed

jscomp/runtime/caml_obj.ml

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ let rec caml_compare (a : Caml_obj_extern.t) (b : Caml_obj_extern.t) : int =
232232
if len_a = len_b then
233233
if O.isArray(a)
234234
then aux_same_length a b 0 len_a
235+
else if [%raw{|a instanceof Date && b instanceof Date|}] then
236+
[%raw{|a - b|}]
235237
else aux_obj_compare a b
236238
else if len_a < len_b then
237239
aux_length_a_short a b 0 len_a
@@ -327,6 +329,8 @@ let rec caml_equal (a : Caml_obj_extern.t) (b : Caml_obj_extern.t) : bool =
327329
if len_a = len_b then
328330
if O.isArray(a)
329331
then aux_equal_length a b 0 len_a
332+
else if [%raw{|a instanceof Date && b instanceof Date|}] then
333+
not (Js.unsafe_gt a b || Js.unsafe_lt a b)
330334
else aux_obj_equal a b
331335
else false
332336
and aux_equal_length (a : Caml_obj_extern.t) (b : Caml_obj_extern.t) i same_length =

jscomp/test/js_date_test.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var Mt = require("./mt.js");
44
var Block = require("../../lib/js/block.js");
5+
var Caml_obj = require("../../lib/js/caml_obj.js");
56

67
function date(param) {
78
return new Date("1976-03-08T12:34:56.789+01:23");
@@ -941,7 +942,18 @@ var suites_001 = /* :: */[
941942
]);
942943
})
943944
],
944-
/* [] */0
945+
/* :: */[
946+
/* tuple */[
947+
"eq",
948+
(function (param) {
949+
var a = new Date("2013-03-01T01:10:00");
950+
var b = new Date("2013-03-01T01:10:00");
951+
var c = new Date("2013-03-01T01:10:01");
952+
return /* Ok */Block.__(4, [Caml_obj.caml_equal(a, b) && Caml_obj.caml_notequal(b, c) && Caml_obj.caml_greaterthan(c, b)]);
953+
})
954+
],
955+
/* [] */0
956+
]
945957
]
946958
]
947959
]
@@ -1015,6 +1027,9 @@ var suites = /* :: */[
10151027

10161028
Mt.from_pair_suites("Js_date_test", suites);
10171029

1030+
var N = 0;
1031+
1032+
exports.N = N;
10181033
exports.date = date;
10191034
exports.suites = suites;
10201035
/* Not a pure module */

0 commit comments

Comments
 (0)