]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Merging in changes for 1.5.2
authorTim Wood <washwithcare@gmail.com>
Mon, 23 Apr 2012 23:25:34 +0000 (16:25 -0700)
committerTim Wood <washwithcare@gmail.com>
Mon, 23 Apr 2012 23:25:34 +0000 (16:25 -0700)
moment.js
test/moment/create.js
test/moment/diff.js

index adea93514436b0820aa172a72886929cfa762627..794f48052044eb7feabac12169df00d148178a9d 100644 (file)
--- a/moment.js
+++ b/moment.js
         },
 
         diff : function (input, val, asFloat) {
-            var inputMoment = moment(input),
+            var inputMoment = this._isUTC ? moment(input).utc() : moment(input).local(),
                 zoneDiff = (this.zone() - inputMoment.zone()) * 6e4,
                 diff = this._d - inputMoment._d - zoneDiff,
                 year = this.year() - inputMoment.year(),
             if (val === 'months') {
                 output = year * 12 + month + date / 30;
             } else if (val === 'years') {
-                output = year + month / 12;
+                output = year + (month + date / 30) / 12;
             } else {
                 output = val === 'seconds' ? diff / 1e3 : // 1000
                     val === 'minutes' ? diff / 6e4 : // 1000 * 60
index 6f10f190622aaa03a3fe2044050cbcf4c2ad7de6..88b520135020b7bc1e8631a0394a741a0d3189de 100644 (file)
@@ -195,6 +195,21 @@ exports.create = {
         test.done();
     },
 
+    "cloning carrying over utc mode" : function(test) {
+        test.expect(8);
+
+        test.equal(moment().local().clone()._isUTC, false, "An explicit cloned local moment should have _isUTC == false");
+        test.equal(moment().utc().clone()._isUTC, true, "An cloned utc moment should have _isUTC == true");
+        test.equal(moment().clone()._isUTC, false, "An explicit cloned local moment should have _isUTC == false");
+        test.equal(moment.utc().clone()._isUTC, true, "An explicit cloned utc moment should have _isUTC == true");
+        test.equal(moment(moment().local())._isUTC, false, "An implicit cloned local moment should have _isUTC == false");
+        test.equal(moment(moment().utc())._isUTC, true, "An implicit cloned utc moment should have _isUTC == true");
+        test.equal(moment(moment())._isUTC, false, "An implicit cloned local moment should have _isUTC == false");
+        test.equal(moment(moment.utc())._isUTC, true, "An implicit cloned utc moment should have _isUTC == true");
+
+        test.done();
+    },
+
     "parsing iso" : function(test) {
         var offset = moment([2011, 9, 08]).zone();
         var pad = function(input) {
index 9170ea7ac5579614e4382da432b0e9824f8467b5..504d1649706ee733251891bfa37a312f8d5b57b9 100644 (file)
@@ -67,6 +67,28 @@ exports.diff = {
         test.equal(moment([2010, 0, 2]).diff([2010], 'hours'), 24, "hour diff");
         test.equal(moment([2010, 0, 1, 2]).diff([2010], 'minutes'), 120, "minute diff");
         test.equal(moment([2010, 0, 1, 0, 4]).diff([2010], 'seconds'), 240, "second diff");
+        test.done();
+    },
+
+    "diff between utc and local" : function(test) {
+        test.expect(7);
+
+        test.equal(moment([2011]).utc().diff([2010], 'years'), 1, "year diff");
+        test.equal(moment([2010, 2]).utc().diff([2010], 'months'), 2, "month diff");
+        test.equal(moment([2010, 0, 4]).utc().diff([2010], 'days'), 3, "day diff");
+        test.equal(moment([2010, 0, 21]).utc().diff([2010], 'weeks'), 3, "week diff");
+        test.equal(moment([2010, 0, 1, 4]).utc().diff([2010], 'hours'), 4, "hour diff");
+        test.equal(moment([2010, 0, 1, 0, 5]).utc().diff([2010], 'minutes'), 5, "minute diff");
+        test.equal(moment([2010, 0, 1, 0, 0, 6]).utc().diff([2010], 'seconds'), 6, "second diff");
+
+        test.done();
+    },
+
+    "year diffs include dates" : function(test) {
+        test.expect(1);
+
+        test.ok(moment([2012, 1, 19]).diff(moment([2002, 1, 20]), 'years', true) < 10, "year diff should include date of month");
+
         test.done();
     }
 };