From: Iskren Chernev Date: Fri, 28 Nov 2014 07:10:06 +0000 (-0800) Subject: Switch zone to utcOffset in some tests X-Git-Tag: 2.9.0~23^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f15c472aed0ecebfa87867247b50b9ff2e93c39;p=thirdparty%2Fmoment.git Switch zone to utcOffset in some tests --- diff --git a/test/moment/create.js b/test/moment/create.js index cc766c4c4..e1feebadc 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -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 = [ diff --git a/test/moment/diff.js b/test/moment/diff.js index d5832f252..5aca304c8 100644 --- a/test/moment/diff.js +++ b/test/moment/diff.js @@ -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'); diff --git a/test/moment/format.js b/test/moment/format.js index 68194ba98..e4ae1bdac 100644 --- a/test/moment/format.js +++ b/test/moment/format.js @@ -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); } diff --git a/test/moment/is_same.js b/test/moment/is_same.js index 4028ff343..a6c2b32cf 100644 --- a/test/moment/is_same.js +++ b/test/moment/is_same.js @@ -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(); diff --git a/test/moment/sod_eod.js b/test/moment/sod_eod.js index 3abe43f6c..86af9cc98 100644 --- a/test/moment/sod_eod.js +++ b/test/moment/sod_eod.js @@ -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', diff --git a/test/moment/utc.js b/test/moment/utc.js index 86094622a..d8ea9068b 100644 --- a/test/moment/utc.js +++ b/test/moment/utc.js @@ -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(); },