docs(test): correct UTC Zulu vs ISO+Offset
This commit is contained in:
parent
b5649558b7
commit
ffba59336f
48
test.js
48
test.js
|
@ -6,7 +6,7 @@ function testUtcToTz(t) {
|
||||||
var result = TZ.toTimeZone.apply(TZ, t.inputs).toISOString();
|
var result = TZ.toTimeZone.apply(TZ, t.inputs).toISOString();
|
||||||
if (t.result !== result) {
|
if (t.result !== result) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid UTC to TZ conversion for ${t.desc}:\n` +
|
`Invalid UTC/ISO+Offset to TZ conversion for ${t.desc}:\n` +
|
||||||
`\tExpected: ${t.result}\n` +
|
`\tExpected: ${t.result}\n` +
|
||||||
`\tActual: ${result}\n`
|
`\tActual: ${result}\n`
|
||||||
);
|
);
|
||||||
|
@ -44,23 +44,23 @@ function testTzToUtc(t) {
|
||||||
|
|
||||||
// 12:15am NY -0500 => -0400
|
// 12:15am NY -0500 => -0400
|
||||||
{
|
{
|
||||||
desc: "UTC to 12:15am NY EST",
|
desc: "UTC Zulu to 12:15am NY EST",
|
||||||
inputs: ["2021-03-14T05:15:59.000Z", "America/New_York"],
|
inputs: ["2021-03-14T05:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-03-14T00:15:59.000-0500",
|
result: "2021-03-14T00:15:59.000-0500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 12:15am NY EST (2)",
|
desc: "ISO+Offset to 12:15am NY EST (2)",
|
||||||
inputs: ["2021-03-14T00:15:59.000-0500", "America/New_York"],
|
inputs: ["2021-03-14T00:15:59.000-0500", "America/New_York"],
|
||||||
result: "2021-03-14T00:15:59.000-0500",
|
result: "2021-03-14T00:15:59.000-0500",
|
||||||
},
|
},
|
||||||
// 1:15am NY (non-DST)
|
// 1:15am NY (non-DST)
|
||||||
{
|
{
|
||||||
desc: "UTC to 1:15am NY EST",
|
desc: "UTC Zulu to 1:15am NY EST",
|
||||||
inputs: ["2021-03-14T06:15:59.000Z", "America/New_York"],
|
inputs: ["2021-03-14T06:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-03-14T01:15:59.000-0500",
|
result: "2021-03-14T01:15:59.000-0500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 1:15am NY EST (2)",
|
desc: "ISO+Offset to 1:15am NY EST (2)",
|
||||||
inputs: ["2021-03-14T01:15:59.000-0500", "America/New_York"],
|
inputs: ["2021-03-14T01:15:59.000-0500", "America/New_York"],
|
||||||
result: "2021-03-14T01:15:59.000-0500",
|
result: "2021-03-14T01:15:59.000-0500",
|
||||||
},
|
},
|
||||||
|
@ -69,23 +69,23 @@ function testTzToUtc(t) {
|
||||||
|
|
||||||
// 3:15am NY (DST)
|
// 3:15am NY (DST)
|
||||||
{
|
{
|
||||||
desc: "UTC to 3:15am NY EDT",
|
desc: "UTC Zulu to 3:15am NY EDT",
|
||||||
inputs: ["2021-03-14T07:15:59.000Z", "America/New_York"],
|
inputs: ["2021-03-14T07:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-03-14T03:15:59.000-0400",
|
result: "2021-03-14T03:15:59.000-0400",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 3:15am NY EDT (2)",
|
desc: "ISO+Offset to 3:15am NY EDT (2)",
|
||||||
inputs: ["2021-03-14T03:15:59.000-0400", "America/New_York"],
|
inputs: ["2021-03-14T03:15:59.000-0400", "America/New_York"],
|
||||||
result: "2021-03-14T03:15:59.000-0400",
|
result: "2021-03-14T03:15:59.000-0400",
|
||||||
},
|
},
|
||||||
// 4:15am NY
|
// 4:15am NY
|
||||||
{
|
{
|
||||||
desc: "UTC to 4:15am NY EDT",
|
desc: "UTC Zulu to 4:15am NY EDT",
|
||||||
inputs: ["2021-03-14T08:15:59.000Z", "America/New_York"],
|
inputs: ["2021-03-14T08:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-03-14T04:15:59.000-0400",
|
result: "2021-03-14T04:15:59.000-0400",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 4:15am NY EDT (2)",
|
desc: "ISO+Offset to 4:15am NY EDT (2)",
|
||||||
inputs: ["2021-03-14T04:15:59.000-0400", "America/New_York"],
|
inputs: ["2021-03-14T04:15:59.000-0400", "America/New_York"],
|
||||||
result: "2021-03-14T04:15:59.000-0400",
|
result: "2021-03-14T04:15:59.000-0400",
|
||||||
},
|
},
|
||||||
|
@ -106,57 +106,57 @@ function testTzToUtc(t) {
|
||||||
|
|
||||||
// 12:15am NY -0400 => -0500
|
// 12:15am NY -0400 => -0500
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 12:15am NY EDT",
|
desc: "UTC Zulu to 2021 Nov 7, 12:15am NY EDT",
|
||||||
inputs: ["2021-11-07T04:15:59.000Z", "America/New_York"],
|
inputs: ["2021-11-07T04:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-11-07T00:15:59.000-0400",
|
result: "2021-11-07T00:15:59.000-0400",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 12:15am NY EDT (2)",
|
desc: "ISO+Offset to 2021 Nov 7, 12:15am NY EDT (2)",
|
||||||
inputs: ["2021-11-07T00:15:59.000-0400", "America/New_York"],
|
inputs: ["2021-11-07T00:15:59.000-0400", "America/New_York"],
|
||||||
result: "2021-11-07T00:15:59.000-0400",
|
result: "2021-11-07T00:15:59.000-0400",
|
||||||
},
|
},
|
||||||
// 1:15am NY (DST) -0400
|
// 1:15am NY (DST) -0400
|
||||||
// NOTE: 1:15am happens TWICE (with different offsets)
|
// NOTE: 1:15am happens TWICE (with different offsets)
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 1:15am NY EDT",
|
desc: "UTC Zulu to 2021 Nov 7, 1:15am NY EDT",
|
||||||
inputs: ["2021-11-07T05:15:59.000Z", "America/New_York"],
|
inputs: ["2021-11-07T05:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-11-07T01:15:59.000-0400",
|
result: "2021-11-07T01:15:59.000-0400",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 1:15am NY EDT (2)",
|
desc: "ISO+Offset to 2021 Nov 7, 1:15am NY EDT (2)",
|
||||||
inputs: ["2021-11-07T01:15:59.000-0400", "America/New_York"],
|
inputs: ["2021-11-07T01:15:59.000-0400", "America/New_York"],
|
||||||
result: "2021-11-07T01:15:59.000-0400",
|
result: "2021-11-07T01:15:59.000-0400",
|
||||||
},
|
},
|
||||||
// 1:15am NY (non-DST) -0500
|
// 1:15am NY (non-DST) -0500
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 1:15am NY EST",
|
desc: "UTC Zulu to 2021 Nov 7, 1:15am NY EST",
|
||||||
inputs: ["2021-11-07T06:15:59.000Z", "America/New_York"],
|
inputs: ["2021-11-07T06:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-11-07T01:15:59.000-0500",
|
result: "2021-11-07T01:15:59.000-0500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 1:15am NY EST (2)",
|
desc: "ISO+Offset to 2021 Nov 7, 1:15am NY EST (2)",
|
||||||
inputs: ["2021-11-07T01:15:59.000-0500", "America/New_York"],
|
inputs: ["2021-11-07T01:15:59.000-0500", "America/New_York"],
|
||||||
result: "2021-11-07T01:15:59.000-0500",
|
result: "2021-11-07T01:15:59.000-0500",
|
||||||
},
|
},
|
||||||
// 2:15am NY -0500
|
// 2:15am NY -0500
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 2:15am NY EST",
|
desc: "UTC Zulu to 2021 Nov 7, 2:15am NY EST",
|
||||||
inputs: ["2021-11-07T07:15:59.000Z", "America/New_York"],
|
inputs: ["2021-11-07T07:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-11-07T02:15:59.000-0500",
|
result: "2021-11-07T02:15:59.000-0500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 2:15am NY EST (2)",
|
desc: "ISO+Offset to 2021 Nov 7, 2:15am NY EST (2)",
|
||||||
inputs: ["2021-11-07T02:15:59.000-0500", "America/New_York"],
|
inputs: ["2021-11-07T02:15:59.000-0500", "America/New_York"],
|
||||||
result: "2021-11-07T02:15:59.000-0500",
|
result: "2021-11-07T02:15:59.000-0500",
|
||||||
},
|
},
|
||||||
// 3:15am NY
|
// 3:15am NY
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 3:15am NY EST",
|
desc: "UTC Zulu to 2021 Nov 7, 3:15am NY EST",
|
||||||
inputs: ["2021-11-07T08:15:59.000Z", "America/New_York"],
|
inputs: ["2021-11-07T08:15:59.000Z", "America/New_York"],
|
||||||
result: "2021-11-07T03:15:59.000-0500",
|
result: "2021-11-07T03:15:59.000-0500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to 2021 Nov 7, 3:15am NY EST (2)",
|
desc: "ISO+Offset to 2021 Nov 7, 3:15am NY EST (2)",
|
||||||
inputs: ["2021-11-07T03:15:59.000-0500", "America/New_York"],
|
inputs: ["2021-11-07T03:15:59.000-0500", "America/New_York"],
|
||||||
result: "2021-11-07T03:15:59.000-0500",
|
result: "2021-11-07T03:15:59.000-0500",
|
||||||
},
|
},
|
||||||
|
@ -167,27 +167,27 @@ function testTzToUtc(t) {
|
||||||
|
|
||||||
// Colombo +0530 (not DST)
|
// Colombo +0530 (not DST)
|
||||||
{
|
{
|
||||||
desc: "UTC to Asia/Colombo (1)",
|
desc: "UTC Zulu to Asia/Colombo (1)",
|
||||||
inputs: ["2021-03-14T08:15:59.000Z", "Asia/Colombo"],
|
inputs: ["2021-03-14T08:15:59.000Z", "Asia/Colombo"],
|
||||||
result: "2021-03-14T13:45:59.000+0530",
|
result: "2021-03-14T13:45:59.000+0530",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to Asia/Colombo (2)",
|
desc: "ISO+Offset to Asia/Colombo (2)",
|
||||||
inputs: ["2021-03-14T13:45:59.000+0530", "Asia/Colombo"],
|
inputs: ["2021-03-14T13:45:59.000+0530", "Asia/Colombo"],
|
||||||
result: "2021-03-14T13:45:59.000+0530",
|
result: "2021-03-14T13:45:59.000+0530",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to Asia/Colombo (3)",
|
desc: "UTC Zulu to Asia/Colombo (3)",
|
||||||
inputs: ["2021-11-07T08:15:59.000Z", "Asia/Colombo"],
|
inputs: ["2021-11-07T08:15:59.000Z", "Asia/Colombo"],
|
||||||
result: "2021-11-07T13:45:59.000+0530",
|
result: "2021-11-07T13:45:59.000+0530",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "UTC to Asia/Colombo (4)",
|
desc: "ISO+Offset to Asia/Colombo (4)",
|
||||||
inputs: ["2021-11-07T13:45:59.000+0530", "Asia/Colombo"],
|
inputs: ["2021-11-07T13:45:59.000+0530", "Asia/Colombo"],
|
||||||
result: "2021-11-07T13:45:59.000+0530",
|
result: "2021-11-07T13:45:59.000+0530",
|
||||||
},
|
},
|
||||||
].forEach(testUtcToTz);
|
].forEach(testUtcToTz);
|
||||||
console.info("Pass: UTC to TZ for America/New_York and Asia/Colombo");
|
console.info("Pass: UTC/ISO+Offset to TZ for America/New_York and Asia/Colombo");
|
||||||
|
|
||||||
[
|
[
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue