]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Switch zone to utcOffset in some tests
authorIskren Chernev <iskren.chernev@gmail.com>
Fri, 28 Nov 2014 07:10:06 +0000 (23:10 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 24 Dec 2014 21:29:52 +0000 (13:29 -0800)
test/moment/create.js
test/moment/diff.js
test/moment/format.js
test/moment/is_same.js
test/moment/sod_eod.js
test/moment/utc.js

index cc766c4c483081d48624bcc3656642e204fea506..e1feebadc456b8a6be21b42edde58d488b8d1549 100644 (file)
@@ -486,16 +486,18 @@ exports.create = {
     },
 
     'parsing iso' : function (test) {
-        var offset = moment([2011, 9, 8]).zone(),
+        var offset = moment([2011, 9, 8]).utcOffset(),
             pad = function (input) {
                 if (input < 10) {
                     return '0' + input;
                 }
                 return '' + input;
             },
-            hourOffset = (offset > 0) ? Math.floor(offset / 60) : Math.ceil(offset / 60),
+            hourOffset = (offset > 0 ? Math.floor(offset / 60) : Math.ceil(offset / 60)),
             minOffset = offset - (hourOffset * 60),
-            tz = (offset > 0) ? '-' + pad(hourOffset) + ':' + pad(minOffset) : '+' + pad(-hourOffset) + ':' + pad(-minOffset),
+            tz = (offset > 0 ?
+                    '+' + pad(hourOffset) + ':' + pad(minOffset) :
+                    '-' + pad(-hourOffset) + ':' + pad(-minOffset)),
             tz2 = tz.replace(':', ''),
             tz3 = tz2.slice(0, 3),
             formats = [
index d5832f252181d82ab6724f0ad55e91cc5f02729a..5aca304c8858004225ab9b6bc67db659fedd8e0d 100644 (file)
@@ -13,7 +13,7 @@ function dstForYear(year) {
     while (current < end) {
         last = current.clone();
         current.add(24, 'hour');
-        if (last.zone() !== current.zone()) {
+        if (last.utcOffset() !== current.utcOffset()) {
             end = current.clone();
             current = last.clone();
             break;
@@ -23,10 +23,10 @@ function dstForYear(year) {
     while (current < end) {
         last = current.clone();
         current.add(1, 'hour');
-        if (last.zone() !== current.zone()) {
+        if (last.utcOffset() !== current.utcOffset()) {
             return {
                 moment : last,
-                diff : (current.zone() - last.zone()) / 60
+                diff : -(current.utcOffset() - last.utcOffset()) / 60
             };
         }
     }
@@ -174,8 +174,8 @@ exports.diff = {
     },
 
     'diff between utc and local' : function (test) {
-        if (moment([2012]).zone() === moment([2011]).zone()) {
-            // Russia's zone offset on 1st of Jan 2012 vs 2011 is different
+        if (moment([2012]).utcOffset() === moment([2011]).utcOffset()) {
+            // Russia's utc offset on 1st of Jan 2012 vs 2011 is different
             test.equal(moment([2012]).utc().diff([2011], 'years'), 1, 'year diff');
         }
         test.equal(moment([2010, 2, 2]).utc().diff([2010, 0, 2], 'months'), 2, 'month diff');
index 68194ba98bb3d4be38140c1f45aa41c232901a7d..e4ae1bdacbffba8e8b40b4c63c6deae1fabf659f 100644 (file)
@@ -69,17 +69,13 @@ exports.format = {
     'format timezone' : function (test) {
         test.expect(2);
 
-        var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
-            explanation = 'moment().format(\'z\') = ' + b.format('z') + ' It should be something like \'PST\'';
-        if (moment().zone() === -60) {
-            explanation += 'For UTC+1 this is a known issue, see https://github.com/timrwood/moment/issues/162';
-        }
+        var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125));
         test.ok(b.format('Z').match(/^[\+\-]\d\d:\d\d$/), b.format('Z') + ' should be something like \'+07:30\'');
         test.ok(b.format('ZZ').match(/^[\+\-]\d{4}$/), b.format('ZZ') + ' should be something like \'+0700\'');
         test.done();
     },
 
-    'format multiple with zone' : function (test) {
+    'format multiple with utc offset' : function (test) {
         test.expect(1);
 
         var b = moment('2012-10-08 -1200', ['YYYY-MM-DD HH:mm ZZ', 'YYYY-MM-DD ZZ', 'YYYY-MM-DD']);
@@ -140,24 +136,13 @@ exports.format = {
         test.done();
     },
 
-    'zone' : function (test) {
-        test.expect(3);
+    'utcOffset sanity checks': function (test) {
+        test.equal(moment().utcOffset() % 15, 0,
+                'utc offset should be a multiple of 15 (was ' + moment().utcOffset() + ')');
+
+        test.equal(moment().utcOffset(), -(new Date()).getTimezoneOffset(),
+            'utcOffset should return the opposite of getTimezoneOffset');
 
-        if (moment().zone() > 0) {
-            test.ok(moment().format('ZZ').indexOf('-') > -1, 'When the zone() offset is greater than 0, the ISO offset should be less than zero');
-        }
-        if (moment().zone() < 0) {
-            test.ok(moment().format('ZZ').indexOf('+') > -1, 'When the zone() offset is less than 0, the ISO offset should be greater than zero');
-        }
-        if (moment().zone() === 0) {
-            test.ok(moment().format('ZZ').indexOf('+') > -1, 'When the zone() offset is equal to 0, the ISO offset should be positive zero');
-        }
-        if (moment().zone() === 0) {
-            test.equal(moment().zone(), 0, 'moment.fn.zone should be a multiple of 15 (was ' + moment().zone() + ')');
-        } else {
-            test.equal(moment().zone() % 15, 0, 'moment.fn.zone should be a multiple of 15 (was ' + moment().zone() + ')');
-        }
-        test.equal(moment().zone(), new Date().getTimezoneOffset(), 'zone should equal getTimezoneOffset');
         test.done();
     },
 
@@ -395,8 +380,8 @@ exports.format = {
 
         for (i = 0; i < zones.length; ++i) {
             z = zones[i];
-            a = moment().zone(z).startOf('day').subtract({m: 1});
-            test.equal(moment(a).zone(z).calendar(), 'Yesterday at 11:59 PM',
+            a = moment().utcOffset(z).startOf('day').subtract({m: 1});
+            test.equal(moment(a).utcOffset(z).calendar(), 'Yesterday at 11:59 PM',
                     'Yesterday at 11:59 PM, not Today, or the wrong time, tz = ' + z);
         }
 
index 4028ff343f5bc67a2bdbc09e5b4082b08b9ede48..a6c2b32cf21cbb35bc71775d394f0380cfe27493 100644 (file)
@@ -168,10 +168,10 @@ exports.isSame = {
         test.done();
     },
 
-    'is same with zone\'d moments' : function (test) {
+    'is same with utc offset moments' : function (test) {
         test.expect(3);
         test.ok(moment.parseZone('2013-02-01T-05:00').isSame(moment('2013-02-01'), 'year'), 'zoned vs local moment');
-        test.ok(moment('2013-02-01').isSame(moment('2013-02-01').zone('-05:00'), 'year'), 'local vs zoned moment');
+        test.ok(moment('2013-02-01').isSame(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
         test.ok(moment.parseZone('2013-02-01T-05:00').isSame(moment.parseZone('2013-02-01T-06:30'), 'year'),
                 'zoned vs (differently) zoned moment');
         test.done();
index 3abe43f6ccfa26d94ed67f55dca62627451e2fae..86af9cc9856088bf83dbdc5b778abc1bcd533d71 100644 (file)
@@ -352,9 +352,9 @@ exports.endStartOf = {
 
         moment.updateOffset = function (mom, keepTime) {
             if (mom.isBefore(dstAt)) {
-                mom.zone(8, keepTime);
+                mom.utcOffset(-8, keepTime);
             } else {
-                mom.zone(7, keepTime);
+                mom.utcOffset(-7, keepTime);
             }
         };
 
@@ -393,9 +393,9 @@ exports.endStartOf = {
 
         moment.updateOffset = function (mom, keepTime) {
             if (mom.isBefore(dstAt)) {
-                mom.zone(7, keepTime);
+                mom.utcOffset(-7, keepTime);
             } else {
-                mom.zone(8, keepTime);
+                mom.utcOffset(-8, keepTime);
             }
         };
 
@@ -409,13 +409,13 @@ exports.endStartOf = {
         test.equal(m.format(), '2014-11-02T00:00:00-07:00',
                 'startOf(\'day\') across -1');
 
-        // note that zone is -8
+        // note that utc offset is -8
         m = moment('2014-11-02T01:30:00-08:00').parseZone();
         m.startOf('h');
         test.equal(m.format(), '2014-11-02T01:00:00-08:00',
                 'startOf(\'hour\') after +1');
 
-        // note that zone is -7
+        // note that utc offset is -7
         m = moment('2014-11-02T01:30:00-07:00').parseZone();
         m.startOf('h');
         test.equal(m.format(), '2014-11-02T01:00:00-07:00',
index 86094622ab4013a8f7ae998468cfdc15258c5c3c..d8ea9068bd434aa16ce65b0ff22bf970e3fca342 100644 (file)
@@ -18,7 +18,7 @@ exports.utc = {
     'utc and local' : function (test) {
         test.expect(7);
 
-        var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), zone, expected;
+        var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), offset, expected;
         m.utc();
         // utc
         test.equal(m.date(), 2, 'the day should be correct for utc');
@@ -27,17 +27,17 @@ exports.utc = {
 
         // local
         m.local();
-        if (m.zone() > 180) {
+        if (m.utcOffset() < -180) {
             test.equal(m.date(), 1, 'the date should be correct for local');
             test.equal(m.day(), 2, 'the day should be correct for local');
         } else {
             test.equal(m.date(), 2, 'the date should be correct for local');
             test.equal(m.day(), 3, 'the day should be correct for local');
         }
-        zone = Math.ceil(m.zone() / 60);
-        expected = (24 + 3 - zone) % 24;
+        offset = Math.ceil(m.utcOffset() / 60);
+        expected = (24 + 3 + offset) % 24;
         test.equal(m.hours(), expected, 'the hours (' + m.hours() + ') should be correct for local');
-        test.equal(moment().utc().zone(), 0, 'timezone in utc should always be zero');
+        test.equal(moment().utc().utcOffset(), 0, 'timezone in utc should always be zero');
 
         test.done();
     },
@@ -87,16 +87,16 @@ exports.utc = {
         test.done();
     },
 
-    'cloning with utc' : function (test) {
+    'cloning with utc offset' : function (test) {
         test.expect(4);
 
         var m = moment.utc('2012-01-02T08:20:00');
-        test.equal(moment.utc(m)._isUTC, true, 'the local zone should be converted to UTC');
-        test.equal(moment.utc(m.clone().utc())._isUTC, true, 'the local zone should stay in UTC');
+        test.equal(moment.utc(m)._isUTC, true, 'the local offset should be converted to UTC');
+        test.equal(moment.utc(m.clone().utc())._isUTC, true, 'the local offset should stay in UTC');
 
-        m.zone(120);
-        test.equal(moment.utc(m)._isUTC, true, 'the explicit zone should stay in UTC');
-        test.equal(moment.utc(m).zone(), 0, 'the explicit zone should have an offset of 0');
+        m.utcOffset(120);
+        test.equal(moment.utc(m)._isUTC, true, 'the explicit utc offset should stay in UTC');
+        test.equal(moment.utc(m).utcOffset(), 0, 'the explicit utc offset should have an offset of 0');
 
         test.done();
     },