browser-tz
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -33,3 +33,6 @@ var moment = require("moment-timezone/moment-timezone.js") | ||
function setCorrectLocalTime(time, isoDate) { | ||
// console.log("setCorrectLocalTime", String(time), isoDate) | ||
// time.minute(isoDate.minute) | ||
time.date(isoDate.day) | ||
// console.log("parseToMoment.first-day", String(time)) | ||
@@ -43,2 +46,6 @@ // go back an extra hour to jump over the Timezone gap | ||
// if (time.minute() !== isoDate.minute) { | ||
// time.minute(isoDate.minute) | ||
// } | ||
if (time.date() !== isoDate.day) { | ||
@@ -57,3 +64,3 @@ // since we are jumping an extra hour back to favor the | ||
var secondHour, thirdHour | ||
var latterZone, earlierZone | ||
@@ -65,6 +72,17 @@ if (time.hour() !== isoDate.hour) { | ||
time.hour(isoDate.hour) | ||
secondHour = time.hour() | ||
latterZone = time.zone() | ||
// console.log("parseToMoment.second-hour", String(time)) | ||
} | ||
if (time.minute() !== isoDate.minute) { | ||
// We set the minute as late as we can after having done two | ||
// hour setting hops. This means that we have already crossed | ||
// the TZ gap and the minute cannot be unset to the incorrect | ||
// minute by a TZ gap. If we set this earlier then setting | ||
// the hour might cause a TZ change (DST) and thus set | ||
// the minute to a different value | ||
time.minute(isoDate.minute) | ||
// console.log("parseToMoment.first-minute", String(time)) | ||
} | ||
if (time.hour() !== isoDate.hour) { | ||
@@ -78,3 +96,3 @@ // We may not have actually passed over the TZ if we | ||
time.hour(isoDate.hour) | ||
thirdHour = time.hour() | ||
earlierZone = time.zone() | ||
// console.log("parseToMoment.third-hour", String(time)) | ||
@@ -88,13 +106,9 @@ } | ||
// 1.59am to 3.01am | ||
// The correct behaviour we want is to set the hour | ||
// to the later one which is the secondHour variable | ||
time.hour(secondHour) | ||
// we have to set the hour twice to get it to converge | ||
// properly to the correct hour since we jumped across | ||
// a timezone change again | ||
time.hour(secondHour) | ||
// Moment goes back a timezone offset when this happens. | ||
// The correct thing to do here is to go forward a | ||
// DST offset so we should add the DST offset | ||
var offset = (earlierZone - latterZone) | ||
time.minute(time.minute() + offset) | ||
// console.log("parseToMoment.fourth-hour", String(time)) | ||
} | ||
time.minute(isoDate.minute) | ||
} |
{ | ||
"name": "browser-tz", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Timezone specific manipulation of datetime strings", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -64,2 +64,15 @@ var test = require("tape") | ||
assert.equal(tz.addSecond({ | ||
iso: "2013-04-06T15:00:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}, -30), "2013-04-07T01:59:30.000+11:00") | ||
assert.equal(tz.addSecond({ | ||
iso: "2013-04-06T15:00:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}, -60), "2013-04-07T01:59:00.000+11:00") | ||
assert.equal(tz.addSecond({ | ||
iso: "2013-04-06T15:00:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}, -90), "2013-04-07T01:58:30.000+11:00") | ||
assertDSTBoundary(assert, "second", { | ||
@@ -100,2 +113,12 @@ iso: "2013-11-03T06:00:00Z", | ||
}) | ||
// assertDSTBoundary(assert, "minute", { | ||
// iso: "2013-10-05T15:30:00Z", | ||
// timezone: "Australia/Lord_Howe" | ||
// }) | ||
// console.log("Australia/Lord_Howe --------------------------") | ||
// assertDSTBoundary(assert, "minute", { | ||
// iso: "2013-04-06T15:00:00Z", | ||
// timezone: "Australia/Lord_Howe" | ||
// }) | ||
// console.log("Australia/Lord_Howe --------------------------") | ||
@@ -102,0 +125,0 @@ assert.end() |
@@ -138,2 +138,86 @@ var test = require("tape") | ||
test("tz.IsoString ambigious dates for +30m/-30m DST", function (assert) { | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-05T15:29:59Z", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T01:59:59.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-05T15:30:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T02:30:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-05T15:31:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T02:31:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-06T14:31:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:31:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-06T14:59:59Z", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:59:59.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-06T15:00:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:30:00.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-06T15:01:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}),"2013-04-07T01:31:00.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T01:20:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:20:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T02:00:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T02:00:00.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T02:20:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T02:20:00.000+10:30") | ||
// ambigious | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T01:30:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:30:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T01:45:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:45:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T01:30:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T01:30:00.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T01:59:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T01:59:00.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T02:30:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T02:30:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T03:00:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T03:00:00.000+11:00") | ||
// ambigious | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T02:00:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T02:30:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T02:15:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T02:45:00.000+11:00") | ||
assert.end() | ||
}) | ||
// function printLine(word,end) { | ||
@@ -140,0 +224,0 @@ // console.log("--------------------------" + |
@@ -6,6 +6,31 @@ var test = require("tape") | ||
test("single test", function (assert) { | ||
assert.equal(tz.addWeek({ | ||
iso: "2013-10-20T06:00:00.000Z", | ||
console.log("----------------------- Australia/Lord_Howe -----------------") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T02:00:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T02:30:00.000+11:00") | ||
console.log("----------------------- America/Toronto ---------------------") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-03-10T02:00:00", | ||
timezone: "America/Toronto" | ||
}, 2), "2013-11-03T02:00:00.000-05:00") | ||
}), "2013-03-10T03:00:00.000-04:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T02:00:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T02:00:00.000+10:30") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-04-07T01:20:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-04-07T01:20:00.000+11:00") | ||
assert.equal(tz.IsoString({ | ||
iso: "2013-10-06T03:00:00", | ||
timezone: "Australia/Lord_Howe" | ||
}), "2013-10-06T03:00:00.000+11:00") | ||
assert.equal(tz.addSecond({ | ||
iso: "2013-10-05T15:30:00Z", | ||
timezone: "Australia/Lord_Howe" | ||
}, -30), "2013-04-07T01:59:30.000+11:00") | ||
// console.log("correct time", tz.IsoString({ | ||
@@ -12,0 +37,0 @@ // iso: "2013-03-10T02:00:00:00.000", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48069
991