From 75671cad9b80591acb065204cf141bb6540d75e1 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Mon, 30 Jun 2014 12:58:51 -0700 Subject: [PATCH 1/3] Add failing tests for moving invalid input times forward. --- tests/moment-timezone/parse.js | 68 +++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/tests/moment-timezone/parse.js b/tests/moment-timezone/parse.js index b26529f2..05aa4739 100644 --- a/tests/moment-timezone/parse.js +++ b/tests/moment-timezone/parse.js @@ -11,7 +11,9 @@ exports.parse = { done(); }, - "ambiguous input losing an hour - America/Los_Angeles" : function (t) { + "invalid input - moveInvalidForward : false - Los Angeles" : function (t) { + moment.tz.moveInvalidForward = false; + // the hour from 2am to 3am does not exist on March 11 2011 in America/Los_Angeles var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/Los_Angeles"), atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/Los_Angeles"), @@ -19,19 +21,21 @@ exports.parse = { after = moment.tz([2012, 2, 11, 3, 0, 0], "America/Los_Angeles"); t.equal( before.format("HH mm ss Z"), "01 59 59 -08:00", "Before the lost hour, the time should match the input time"); - t.equal(atStart.format("HH mm ss Z"), "01 00 00 -08:00", "During the lost hour, the time should fall back to the previous time"); - t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the lost hour, the time should fall back to the previous time"); - t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "01 00 00 -08:00", "During the lost hour, the time should roll back to the previous time"); + t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the lost hour, the time should roll back to the previous time"); + t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); t.equal( before.zone(), 480, "Before the lost hour, the offset should match the non-dst offset"); t.equal(atStart.zone(), 480, "During the lost hour, the offset should match the non-dst offset"); t.equal( atEnd.zone(), 480, "During the lost hour, the offset should match the non-dst offset"); - t.equal( after.zone(), 420, "After the lost hour, the time should match the dst offset"); + t.equal( after.zone(), 420, "After the lost hour, the offset should match the dst offset"); t.done(); }, - "ambiguous input losing an hour - America/New_York" : function (t) { + "invalid input - moveInvalidForward : false - New York" : function (t) { + moment.tz.moveInvalidForward = false; + // the hour from 2am to 3am does not exist on March 11 2011 in America/New_York var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/New_York"), atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/New_York"), @@ -39,14 +43,58 @@ exports.parse = { after = moment.tz([2012, 2, 11, 3, 0, 0], "America/New_York"); t.equal( before.format("HH mm ss Z"), "01 59 59 -05:00", "Before the lost hour, the time should match the input time"); - t.equal(atStart.format("HH mm ss Z"), "01 00 00 -05:00", "During the lost hour, the time should fall back to the previous time"); - t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the lost hour, the time should fall back to the previous time"); - t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "01 00 00 -05:00", "During the lost hour, the time should roll back to the previous time"); + t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the lost hour, the time should roll back to the previous time"); + t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); t.equal( before.zone(), 300, "Before the lost hour, the offset should match the non-dst offset"); t.equal(atStart.zone(), 300, "During the lost hour, the offset should match the non-dst offset"); t.equal( atEnd.zone(), 300, "During the lost hour, the offset should match the non-dst offset"); - t.equal( after.zone(), 240, "After the lost hour, the time should match the dst offset"); + t.equal( after.zone(), 240, "After the lost hour, the offset should match the dst offset"); + + t.done(); + }, + + "invalid input - moveInvalidForward : true - Los Angeles" : function (t) { + moment.tz.moveInvalidForward = true; + + // the hour from 2am to 3am does not exist on March 11 2011 in America/Los_Angeles + var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/Los_Angeles"), + atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/Los_Angeles"), + atEnd = moment.tz([2012, 2, 11, 2, 59, 59], "America/Los_Angeles"), + after = moment.tz([2012, 2, 11, 3, 0, 0], "America/Los_Angeles"); + + t.equal( before.format("HH mm ss Z"), "01 59 59 -08:00", "Before the lost hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "03 00 00 -07:00", "During the lost hour, the time should roll forward to the previous time"); + t.equal( atEnd.format("HH mm ss Z"), "03 59 59 -07:00", "During the lost hour, the time should roll forward to the previous time"); + t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); + + t.equal( before.zone(), 480, "Before the lost hour, the offset should match the non-dst offset"); + t.equal(atStart.zone(), 420, "During the lost hour, the offset should match the dst offset"); + t.equal( atEnd.zone(), 420, "During the lost hour, the offset should match the dst offset"); + t.equal( after.zone(), 420, "After the lost hour, the offset should match the dst offset"); + + t.done(); + }, + + "invalid input - moveInvalidForward : true - New York" : function (t) { + moment.tz.moveInvalidForward = true; + + // the hour from 2am to 3am does not exist on March 11 2011 in America/New_York + var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/New_York"), + atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/New_York"), + atEnd = moment.tz([2012, 2, 11, 2, 59, 59], "America/New_York"), + after = moment.tz([2012, 2, 11, 3, 0, 0], "America/New_York"); + + t.equal( before.format("HH mm ss Z"), "01 59 59 -05:00", "Before the lost hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "03 00 00 -04:00", "During the lost hour, the time should roll forward to the previous time"); + t.equal( atEnd.format("HH mm ss Z"), "03 59 59 -04:00", "During the lost hour, the time should roll forward to the previous time"); + t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); + + t.equal( before.zone(), 300, "Before the lost hour, the offset should match the non-dst offset"); + t.equal(atStart.zone(), 240, "During the lost hour, the offset should match the dst offset"); + t.equal( atEnd.zone(), 240, "During the lost hour, the offset should match the dst offset"); + t.equal( after.zone(), 240, "After the lost hour, the offset should match the dst offset"); t.done(); }, From 0bf5b48bddb2f1f118bf3b069ae05e509ae6bd1f Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Mon, 30 Jun 2014 13:03:14 -0700 Subject: [PATCH 2/3] Add failing tests for moving ambiguous input times forward. --- tests/moment-timezone/parse.js | 76 +++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/tests/moment-timezone/parse.js b/tests/moment-timezone/parse.js index 05aa4739..b01051f5 100644 --- a/tests/moment-timezone/parse.js +++ b/tests/moment-timezone/parse.js @@ -11,7 +11,7 @@ exports.parse = { done(); }, - "invalid input - moveInvalidForward : false - Los Angeles" : function (t) { + "invalid input - moveInvalidForward = false - Los Angeles" : function (t) { moment.tz.moveInvalidForward = false; // the hour from 2am to 3am does not exist on March 11 2011 in America/Los_Angeles @@ -33,7 +33,7 @@ exports.parse = { t.done(); }, - "invalid input - moveInvalidForward : false - New York" : function (t) { + "invalid input - moveInvalidForward = false - New York" : function (t) { moment.tz.moveInvalidForward = false; // the hour from 2am to 3am does not exist on March 11 2011 in America/New_York @@ -55,7 +55,7 @@ exports.parse = { t.done(); }, - "invalid input - moveInvalidForward : true - Los Angeles" : function (t) { + "invalid input - moveInvalidForward = true - Los Angeles" : function (t) { moment.tz.moveInvalidForward = true; // the hour from 2am to 3am does not exist on March 11 2011 in America/Los_Angeles @@ -77,7 +77,7 @@ exports.parse = { t.done(); }, - "invalid input - moveInvalidForward : true - New York" : function (t) { + "invalid input - moveInvalidForward = true - New York" : function (t) { moment.tz.moveInvalidForward = true; // the hour from 2am to 3am does not exist on March 11 2011 in America/New_York @@ -99,7 +99,9 @@ exports.parse = { t.done(); }, - "ambiguous input gaining an hour - America/Los_Angeles" : function (t) { + "ambiguous input - moveAmbiguousForward = false - Los Angeles" : function (t) { + moment.tz.moveAmbiguousForward = false; + // the hour from 1am to 2am happens twice on Nov 4 2011 in America/Los_Angeles var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/Los_Angeles"), atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/Los_Angeles"), @@ -107,19 +109,21 @@ exports.parse = { after = moment.tz([2012, 10, 4, 2, 0, 0], "America/Los_Angeles"); t.equal( before.format("HH mm ss Z"), "00 59 59 -07:00", "Before the duplicated hour, the time should match the input time"); - t.equal(atStart.format("HH mm ss Z"), "01 00 00 -07:00", "During the duplicated hour, the time should match the input time"); - t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -07:00", "During the duplicated hour, the time should match the input time"); - t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "01 00 00 -07:00", "During the duplicated hour, the time should match the earlier input time"); + t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -07:00", "During the duplicated hour, the time should match the earlier input time"); + t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); t.equal( before.zone(), 420, "Before the duplicated hour, the offset should match the dst offset"); t.equal(atStart.zone(), 420, "During the duplicated hour, the offset should match the dst offset"); t.equal( atEnd.zone(), 420, "During the duplicated hour, the offset should match the dst offset"); - t.equal( after.zone(), 480, "After the duplicated hour, the time should match the non-dst offset"); + t.equal( after.zone(), 480, "After the duplicated hour, the offset should match the non-dst offset"); t.done(); }, - "ambiguous input gaining an hour - America/New_York" : function (t) { + "ambiguous input - moveAmbiguousForward = false - New York" : function (t) { + moment.tz.moveAmbiguousForward = false; + // the hour from 1am to 2am happens twice on Nov 4 2011 in America/Los_Angeles var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/New_York"), atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/New_York"), @@ -127,14 +131,58 @@ exports.parse = { after = moment.tz([2012, 10, 4, 2, 0, 0], "America/New_York"); t.equal( before.format("HH mm ss Z"), "00 59 59 -04:00", "Before the duplicated hour, the time should match the input time"); - t.equal(atStart.format("HH mm ss Z"), "01 00 00 -04:00", "During the duplicated hour, the time should match the input time"); - t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -04:00", "During the duplicated hour, the time should match the input time"); - t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "01 00 00 -04:00", "During the duplicated hour, the time should match the earlier input time"); + t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -04:00", "During the duplicated hour, the time should match the earlier input time"); + t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); t.equal( before.zone(), 240, "Before the duplicated hour, the offset should match the dst offset"); t.equal(atStart.zone(), 240, "During the duplicated hour, the offset should match the dst offset"); t.equal( atEnd.zone(), 240, "During the duplicated hour, the offset should match the dst offset"); - t.equal( after.zone(), 300, "After the duplicated hour, the time should match the non-dst offset"); + t.equal( after.zone(), 300, "After the duplicated hour, the offset should match the non-dst offset"); + + t.done(); + }, + + "ambiguous input - moveAmbiguousForward = true - Los Angeles" : function (t) { + moment.tz.moveAmbiguousForward = true; + + // the hour from 1am to 2am happens twice on Nov 4 2011 in America/Los_Angeles + var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/Los_Angeles"), + atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/Los_Angeles"), + atEnd = moment.tz([2012, 10, 4, 1, 59, 59], "America/Los_Angeles"), + after = moment.tz([2012, 10, 4, 2, 0, 0], "America/Los_Angeles"); + + t.equal( before.format("HH mm ss Z"), "00 59 59 -07:00", "Before the duplicated hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "01 00 00 -08:00", "During the duplicated hour, the time should match the later input time"); + t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the duplicated hour, the time should match the later input time"); + t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); + + t.equal( before.zone(), 420, "Before the duplicated hour, the offset should match the dst offset"); + t.equal(atStart.zone(), 480, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( atEnd.zone(), 480, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( after.zone(), 480, "After the duplicated hour, the offset should match the non-dst offset"); + + t.done(); + }, + + "ambiguous input - moveAmbiguousForward = true - New York" : function (t) { + moment.tz.moveAmbiguousForward = true; + + // the hour from 1am to 2am happens twice on Nov 4 2011 in America/Los_Angeles + var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/New_York"), + atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/New_York"), + atEnd = moment.tz([2012, 10, 4, 1, 59, 59], "America/New_York"), + after = moment.tz([2012, 10, 4, 2, 0, 0], "America/New_York"); + + t.equal( before.format("HH mm ss Z"), "00 59 59 -04:00", "Before the duplicated hour, the time should match the input time"); + t.equal(atStart.format("HH mm ss Z"), "01 00 00 -05:00", "During the duplicated hour, the time should match the later input time"); + t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the duplicated hour, the time should match the later input time"); + t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); + + t.equal( before.zone(), 240, "Before the duplicated hour, the offset should match the dst offset"); + t.equal(atStart.zone(), 300, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( atEnd.zone(), 300, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( after.zone(), 300, "After the duplicated hour, the offset should match the non-dst offset"); t.done(); }, From 162dbb9eddf5e246b718a04e7ef362093afeb788 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Mon, 30 Jun 2014 13:50:29 -0700 Subject: [PATCH 3/3] Passing tests for configuring which offset to use during ambiguous or invalid offsets --- moment-timezone.js | 21 ++++++++++++++++++--- tests/moment-timezone/parse.js | 28 +++++++++++++++++++++++----- tests/moment-timezone/zone.js | 16 ++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/moment-timezone.js b/moment-timezone.js index 8ada6edd..a565a7b8 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -143,13 +143,26 @@ var target = +timestamp, offsets = this.offsets, untils = this.untils, - i; + max = untils.length - 1, + offset, offsetNext, offsetPrev, i; + + for (i = 0; i < max; i++) { + offset = offsets[i]; + offsetNext = offsets[i + 1]; + offsetPrev = offsets[i ? i - 1 : i]; + + if (offset < offsetNext && tz.moveAmbiguousForward) { + offset = offsetNext; + } else if (offset > offsetPrev && tz.moveInvalidForward) { + offset = offsetPrev; + } - for (i = 0; i < untils.length; i++) { - if (target < untils[i] - (offsets[i] * 60000)) { + if (target < untils[i] - (offset * 60000)) { return offsets[i]; } } + + return offsets[max]; }, abbr : function (mom) { @@ -272,6 +285,8 @@ tz.unpack = unpack; tz.unpackBase60 = unpackBase60; tz.needsOffset = needsOffset; + tz.moveInvalidForward = true; + tz.moveAmbiguousForward = false; /************************************ Interface with Moment.js diff --git a/tests/moment-timezone/parse.js b/tests/moment-timezone/parse.js index b01051f5..babd4e35 100644 --- a/tests/moment-timezone/parse.js +++ b/tests/moment-timezone/parse.js @@ -5,12 +5,30 @@ var moment = require("../../index"); var Los_Angeles = "America/Los_Angeles|PST PDT PWT PPT|80 70 70 70|010102301010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-261q0 1nX0 11B0 1nX0 SgN0 8x10 iy0 5Wp0 1Vb0 3dB0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 s10 1Vz0 LB0 1BX0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0"; var New_York = "America/New_York|EST EDT EWT EPT|50 40 40 40|01010101010101010101010101010101010101010101010102301010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-261t0 1nX0 11B0 1nX0 11B0 1qL0 1a10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 RB0 8x40 iv0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 s10 1Vz0 LB0 1BX0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0"; +var moveAmbiguousForward, moveInvalidForward; + exports.parse = { setUp : function (done) { moment.tz.add([Los_Angeles, New_York]); + + moveAmbiguousForward = moment.tz.moveAmbiguousForward; + moveInvalidForward = moment.tz.moveInvalidForward; + done(); + }, + + tearDown : function (done) { + moment.tz.moveAmbiguousForward = moveAmbiguousForward; + moment.tz.moveInvalidForward = moveInvalidForward; done(); }, + "default states" : function (t) { + t.ok(moment.tz.moveInvalidForward, "Should default to moving invalid input forward"); + t.ok(!moment.tz.moveAmbiguousForward, "Should default to moving ambiguous input backward"); + + t.done(); + }, + "invalid input - moveInvalidForward = false - Los Angeles" : function (t) { moment.tz.moveInvalidForward = false; @@ -56,7 +74,7 @@ exports.parse = { }, "invalid input - moveInvalidForward = true - Los Angeles" : function (t) { - moment.tz.moveInvalidForward = true; + // moment.tz.moveInvalidForward = true; Should default to true // the hour from 2am to 3am does not exist on March 11 2011 in America/Los_Angeles var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/Los_Angeles"), @@ -78,7 +96,7 @@ exports.parse = { }, "invalid input - moveInvalidForward = true - New York" : function (t) { - moment.tz.moveInvalidForward = true; + // moment.tz.moveInvalidForward = true; Should default to true // the hour from 2am to 3am does not exist on March 11 2011 in America/New_York var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/New_York"), @@ -100,7 +118,7 @@ exports.parse = { }, "ambiguous input - moveAmbiguousForward = false - Los Angeles" : function (t) { - moment.tz.moveAmbiguousForward = false; + // moment.tz.moveAmbiguousForward = false; Should default to false // the hour from 1am to 2am happens twice on Nov 4 2011 in America/Los_Angeles var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/Los_Angeles"), @@ -122,7 +140,7 @@ exports.parse = { }, "ambiguous input - moveAmbiguousForward = false - New York" : function (t) { - moment.tz.moveAmbiguousForward = false; + // moment.tz.moveAmbiguousForward = false; Should default to false // the hour from 1am to 2am happens twice on Nov 4 2011 in America/Los_Angeles var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/New_York"), @@ -206,5 +224,5 @@ exports.parse = { } t.done(); - }, + } }; diff --git a/tests/moment-timezone/zone.js b/tests/moment-timezone/zone.js index d31cce2c..8dac8c14 100644 --- a/tests/moment-timezone/zone.js +++ b/tests/moment-timezone/zone.js @@ -5,7 +5,21 @@ var tz = require("../../").tz; // gE = 1000; 1E = 100; 2k = 140 var PACKED = "SomeZone|TIM TAM IAM|60.u 50 60|012101|gE 1E 2k 1E 2k"; +var moveAmbiguousForward, moveInvalidForward; + exports.zone = { + setUp : function (done) { + moveAmbiguousForward = tz.moveAmbiguousForward; + moveInvalidForward = tz.moveInvalidForward; + done(); + }, + + tearDown : function (done) { + tz.moveAmbiguousForward = moveAmbiguousForward; + tz.moveInvalidForward = moveInvalidForward; + done(); + }, + construct : function (test) { var zone = new tz.Zone(PACKED); @@ -121,6 +135,8 @@ exports.zone = { [(1480 - 360.5) * 60000, 300] ], i, source, expected; + tz.moveInvalidForward = false; + for (i = 0; i < tests.length; i++) { source = tests[i][0]; expected = tests[i][1];