docs+test: toUTC => fromTimeZone, correct UTC vs ISO

This commit is contained in:
AJ ONeal 2022-03-09 23:59:02 -07:00
parent ffba59336f
commit 6417eca7f6
No known key found for this signature in database
GPG Key ID: 585419CA6DB0AA23
2 changed files with 11 additions and 8 deletions

View File

@ -22,9 +22,9 @@ var XTZ;
console.info(); console.info();
console.info("\t// during daylight savings"); console.info("\t// during daylight savings");
console.info(`\tXTZ.toUTC("2021-03-14 08:15:59.000", "America/New_York")`); console.info(`\tXTZ.fromTimeZone("2021-03-14 08:15:59.000", "America/New_York")`);
console.info(`\ttzDate.toISOString()`); console.info(`\ttzDate.toISOString()`);
tzDate = XTZ.toUTC("2021-03-14 08:15:59.000", "America/New_York"); tzDate = XTZ.fromTimeZone("2021-03-14 08:15:59.000", "America/New_York");
console.info( console.info(
"\t" + tzDate.toISOString(), "\t" + tzDate.toISOString(),
"// same as", "// same as",
@ -33,9 +33,9 @@ var XTZ;
console.info(); console.info();
console.info("\t// during standard time"); console.info("\t// during standard time");
console.info(`\tXTZ.toUTC("2021-11-07 08:15:59.000", "America/New_York")`); console.info(`\tXTZ.fromTimeZone("2021-11-07 08:15:59.000", "America/New_York")`);
console.info(`\ttzDate.toISOString()`); console.info(`\ttzDate.toISOString()`);
tzDate = XTZ.toUTC("2021-11-07 08:15:59.000", "America/New_York"); tzDate = XTZ.fromTimeZone("2021-11-07 08:15:59.000", "America/New_York");
console.info( console.info(
"\t" + tzDate.toISOString(), "\t" + tzDate.toISOString(),
"// same as", "// same as",
@ -65,9 +65,9 @@ var XTZ;
console.info(); console.info();
console.info("\t// during standard time"); console.info("\t// during standard time");
console.info(`\tXTZ.toUTC("2021-11-07T08:15:59.000Z", "America/New_York")`); console.info(`\tXTZ.fromTimeZone("2021-11-07T08:15:59.000Z", "America/New_York")`);
console.info(`\ttzDate.toISOString()`); console.info(`\ttzDate.toISOString()`);
tzDate = XTZ.toUTC("2021-11-07T08:15:59.000Z", "America/New_York"); tzDate = XTZ.fromTimeZone("2021-11-07T08:15:59.000Z", "America/New_York");
console.info( console.info(
"\t" + tzDate.toISOString(), "\t" + tzDate.toISOString(),
"// same as", "// same as",

View File

@ -15,7 +15,8 @@ function testUtcToTz(t) {
function testTzToUtc(t) { function testTzToUtc(t) {
var result = TZ.toUTC.apply(TZ, t.inputs); var result = TZ.toUTC.apply(TZ, t.inputs);
if (t.result !== result.toISOString()) { var result2 = TZ.fromTimeZone.apply(TZ, t.inputs);
if (t.result !== result.toISOString() || t.result !== result2.toISOString()) {
console.log(result); console.log(result);
throw new Error( throw new Error(
`Invalid TZ to UTC conversion for ${t.desc}:\n` + `Invalid TZ to UTC conversion for ${t.desc}:\n` +
@ -187,7 +188,9 @@ function testTzToUtc(t) {
result: "2021-11-07T13:45:59.000+0530", result: "2021-11-07T13:45:59.000+0530",
}, },
].forEach(testUtcToTz); ].forEach(testUtcToTz);
console.info("Pass: UTC/ISO+Offset to TZ for America/New_York and Asia/Colombo"); console.info(
"Pass: UTC/ISO+Offset to TZ for America/New_York and Asia/Colombo"
);
[ [
// //