Compare commits
No commits in common. "f03e75b89899d830c07da8f6619b2c6bf647af53" and "6417eca7f69ba0c7eabdcc92f284ea2397efec59" have entirely different histories.
f03e75b898
...
6417eca7f6
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "xtz",
|
||||
"version": "1.3.2",
|
||||
"version": "1.3.1",
|
||||
"description": "A fast, lightweight, zero-dependency library to translate between Time Zones and UTC with native Intl.DateTimeFormat in ~100 LoC. For Node.js & Browsers.",
|
||||
"main": "xtz.js",
|
||||
"files": [
|
||||
|
|
25
test.js
25
test.js
|
@ -4,8 +4,7 @@ var TZ = require("./");
|
|||
|
||||
function testUtcToTz(t) {
|
||||
var result = TZ.toTimeZone.apply(TZ, t.inputs).toISOString();
|
||||
var result2 = TZ.toTimeZoneISOString.apply(TZ, t.inputs);
|
||||
if (result !== result2 || t.result !== result) {
|
||||
if (t.result !== result) {
|
||||
throw new Error(
|
||||
`Invalid UTC/ISO+Offset to TZ conversion for ${t.desc}:\n` +
|
||||
`\tExpected: ${t.result}\n` +
|
||||
|
@ -15,11 +14,10 @@ function testUtcToTz(t) {
|
|||
}
|
||||
|
||||
function testTzToUtc(t) {
|
||||
var result = TZ.fromTimeZone.apply(TZ, t.inputs).toISOString();
|
||||
var result2 = TZ.toOffsetISOString.apply(TZ, t.inputs);
|
||||
var result3 = TZ.toUTC.apply(TZ, t.inputs).toISOString();
|
||||
if (t.result !== result || t.result !== result2 || t.result !== result3) {
|
||||
console.error(result);
|
||||
var result = TZ.toUTC.apply(TZ, t.inputs);
|
||||
var result2 = TZ.fromTimeZone.apply(TZ, t.inputs);
|
||||
if (t.result !== result.toISOString() || t.result !== result2.toISOString()) {
|
||||
console.log(result);
|
||||
throw new Error(
|
||||
`Invalid TZ to UTC conversion for ${t.desc}:\n` +
|
||||
`\tExpected: ${t.result}\n` +
|
||||
|
@ -319,16 +317,3 @@ console.info(
|
|||
},
|
||||
].forEach(testTzToUtc);
|
||||
console.info("Pass: TZ to UTC for America/New_York and Asia/Colombo");
|
||||
|
||||
var localISOString = TZ.toLocalISOString();
|
||||
var reISOString = /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d[+-]\d\d\d\d$/;
|
||||
if (!reISOString.test(localISOString)) {
|
||||
throw new Error("Couldn't get local time as iso+offset");
|
||||
}
|
||||
console.info("Pass: can get local time as ISO+Offset");
|
||||
|
||||
var tzName = TZ.timeZone();
|
||||
if (!/^[A-Z]\w+\/[A-Z]\w+$/.test(tzName)) {
|
||||
throw new Error("Couldn't get local Time Zone");
|
||||
}
|
||||
console.info("Pass: can get local timezone");
|
||||
|
|
9
xtz.js
9
xtz.js
|
@ -103,7 +103,7 @@
|
|||
}
|
||||
|
||||
function toOffsetISOString(date, timeZone) {
|
||||
if ("object" === typeof date && "offset" in date && "year" in date) {
|
||||
if ("offset" in date && "year" in date) {
|
||||
return formatAsOffsetISOString(date);
|
||||
}
|
||||
|
||||
|
@ -179,10 +179,6 @@
|
|||
return `${YYYY}-${MM}-${DD}T${hh}:${mm}:${ss}.${sss}${offset}`;
|
||||
}
|
||||
|
||||
function getTimeZone() {
|
||||
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
}
|
||||
|
||||
exports.XTZ = {
|
||||
// bespoke date =>
|
||||
// 2021-11-07T3:15:59-0500
|
||||
|
@ -194,9 +190,6 @@
|
|||
// -240 => -0400
|
||||
formatOffset: formatOffset,
|
||||
|
||||
// "America/New_York"
|
||||
timeZone: getTimeZone,
|
||||
// "2021-11-07T03:15:59-0500"
|
||||
toLocalISOString: toLocalISOString,
|
||||
|
||||
// [ "2021-11-07T08:15:59Z", "America/New_York" ]
|
||||
|
|
Loading…
Reference in New Issue