]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
make diff across DST work 149/head
authorRocky Meza <rocky@fusionbox.com>
Tue, 31 Jan 2012 23:29:20 +0000 (16:29 -0700)
committerRocky Meza <rocky@fusionbox.com>
Tue, 31 Jan 2012 23:29:20 +0000 (16:29 -0700)
moment.js
sitesrc/js/unit-tests.js

index dda6d16b0e6f35d1cdeeacd2da5d6d0fecb23bcf..37fffe2abbea34c69affb9d8439620fab952cd1f 100644 (file)
--- a/moment.js
+++ b/moment.js
 
         diff : function (input, val, asFloat) {
             var inputMoment = moment(input),
-                diff = this._d - inputMoment._d,
+                zoneDiff = (this.zone() - inputMoment.zone()) * 6e4,
+                diff = this._d - inputMoment._d - zoneDiff,
                 year = this.year() - inputMoment.year(),
                 month = this.month() - inputMoment.month(),
                 date = this.date() - inputMoment.date(),
                 output;
+
             if (val === 'months') {
                 output = year * 12 + month + date / 30;
             } else if (val === 'years') {
index ae2f5c66089e61a06d3f304d0e42fac9abe49fd8..c8cb2a98fcd0ebd373e6b12d8f9c3e8688827785 100755 (executable)
@@ -294,8 +294,9 @@ test("diff month", 1, function() {
     equal(moment([2011, 0, 31]).diff([2011, 2, 1], 'months'), -1, "month diff");
 });
 
-test("diff week", 1, function() {
-    equal(moment([2012, 2, 18]).diff([2012], 'weeks'), 12, "week diff");
+test("diff across DST", 2, function() {
+    equal(moment([2012, 2, 24]).diff([2012, 2, 10], 'weeks', true), 2, "diff weeks across DST");
+    equal(moment([2012, 2, 24]).diff([2012, 2, 10], 'days', true), 14, "diff weeks across DST");
 });
 
 test("diff overflow", 4, function() {