]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixed a bug in cloning a Date
authorIskren Chernev <iskren.chernev@gmail.com>
Thu, 14 Feb 2013 05:31:35 +0000 (21:31 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 14 Feb 2013 05:31:35 +0000 (21:31 -0800)
To clone a Date object d you need to convert it to a Number first and then pass
it to Date constructor, like new Date(+d). Otherwise some browsers (firefox)
cut milliseconds.

test/moment/diff.js

index 53049d46d6a9d7077edebeae66a7f83abff2b475..1169e1881e6b0730dbe92231697e336a4d174631 100644 (file)
@@ -13,7 +13,7 @@ exports.diff = {
         test.equal(moment(0).diff(1000), -1000, "0 - 1 second = -1000");
         test.equal(moment(new Date(1000)).diff(1000), 0, "1 second - 1 second = 0");
         var oneHourDate = new Date(),
-        nowDate = new Date(oneHourDate);
+            nowDate = new Date(+oneHourDate);
         oneHourDate.setHours(oneHourDate.getHours() + 1);
         test.equal(moment(oneHourDate).diff(nowDate), 60 * 60 * 1000, "1 hour from now = 360000");
         test.done();