@vvo/tzdb
Advanced tools
Comparing version 6.5.1 to 6.6.0
@@ -16,3 +16,4 @@ "use strict"; | ||
function getTimeZones() { | ||
function getTimeZones(opts) { | ||
const includeUtc = !!opts && opts.includeUtc; | ||
return _rawTimeZones.default.reduce(function (acc, timeZone) { | ||
@@ -41,3 +42,3 @@ const currentDate = _luxon.DateTime.fromObject({ | ||
return acc; | ||
}, []).sort((a, b) => { | ||
}, includeUtc ? [utcTimezone] : []).sort((a, b) => { | ||
return compareNumbers(a, b) || compareStrings(a.alternativeName, b.alternativeName) || compareStrings(a.mainCities[0], b.mainCities[0]); | ||
@@ -58,2 +59,17 @@ }); | ||
} | ||
const utcTimezone = { | ||
name: "UTC", | ||
alternativeName: "Coordinated Universal Time (UTC)", | ||
abbreviation: "UTC", | ||
group: ["UTC"], | ||
countryName: "", | ||
continentCode: "", | ||
continentName: "", | ||
mainCities: [""], | ||
rawOffsetInMinutes: 0, | ||
rawFormat: "+00:00 Coordinated Universal Time (UTC)", | ||
currentTimeOffsetInMinutes: 0, | ||
currentTimeFormat: "+00:00 Coordinated Universal Time (UTC)" | ||
}; | ||
//# sourceMappingURL=getTimeZones.js.map |
@@ -22,4 +22,8 @@ type TimeZoneName = string; | ||
interface TimeZoneOptions { | ||
includeUtc?: boolean; | ||
} | ||
export const rawTimeZones: RawTimeZone[]; | ||
export const timeZonesNames: TimeZoneName[]; | ||
export function getTimeZones(): TimeZone[]; | ||
export function getTimeZones(opts?: TimeZoneOptions): TimeZone[]; |
@@ -22,4 +22,8 @@ type TimeZoneName = string; | ||
interface TimeZoneOptions { | ||
includeUtc?: boolean; | ||
} | ||
export const rawTimeZones: RawTimeZone[]; | ||
export const timeZonesNames: TimeZoneName[]; | ||
export function getTimeZones(): TimeZone[]; | ||
export function getTimeZones(opts?: TimeZoneOptions): TimeZone[]; |
@@ -7,32 +7,36 @@ import { DateTime } from "luxon"; | ||
export default function getTimeZones() { | ||
export default function getTimeZones(opts) { | ||
const includeUtc = !!opts && opts.includeUtc; | ||
return rawTimeZones | ||
.reduce(function (acc, timeZone) { | ||
const currentDate = DateTime.fromObject({ | ||
locale: "en-US", | ||
zone: timeZone.name, | ||
}); | ||
.reduce( | ||
function (acc, timeZone) { | ||
const currentDate = DateTime.fromObject({ | ||
locale: "en-US", | ||
zone: timeZone.name, | ||
}); | ||
// We build on the latest Node.js version, Node.js embed IANA databases | ||
// it might happen that the environment that will execute getTimeZones() will not know about some | ||
// timezones. So we ignore the timezone at runtim | ||
// See https://github.com/vvo/tzdb/issues/43 | ||
if (currentDate.isValid === false) { | ||
return acc; | ||
} | ||
// We build on the latest Node.js version, Node.js embed IANA databases | ||
// it might happen that the environment that will execute getTimeZones() will not know about some | ||
// timezones. So we ignore the timezone at runtim | ||
// See https://github.com/vvo/tzdb/issues/43 | ||
if (currentDate.isValid === false) { | ||
return acc; | ||
} | ||
const timeZoneWithCurrentTimeData = { | ||
...timeZone, | ||
currentTimeOffsetInMinutes: currentDate.offset, | ||
}; | ||
const timeZoneWithCurrentTimeData = { | ||
...timeZone, | ||
currentTimeOffsetInMinutes: currentDate.offset, | ||
}; | ||
acc.push({ | ||
...timeZoneWithCurrentTimeData, | ||
currentTimeFormat: formatTimeZone(timeZoneWithCurrentTimeData, { | ||
useCurrentOffset: true, | ||
}), | ||
}); | ||
acc.push({ | ||
...timeZoneWithCurrentTimeData, | ||
currentTimeFormat: formatTimeZone(timeZoneWithCurrentTimeData, { | ||
useCurrentOffset: true, | ||
}), | ||
}); | ||
return acc; | ||
}, []) | ||
return acc; | ||
}, | ||
includeUtc ? [utcTimezone] : [], | ||
) | ||
.sort((a, b) => { | ||
@@ -57,1 +61,16 @@ return ( | ||
} | ||
const utcTimezone = { | ||
name: "UTC", | ||
alternativeName: "Coordinated Universal Time (UTC)", | ||
abbreviation: "UTC", | ||
group: ["UTC"], | ||
countryName: "", | ||
continentCode: "", | ||
continentName: "", | ||
mainCities: [""], | ||
rawOffsetInMinutes: 0, | ||
rawFormat: "+00:00 Coordinated Universal Time (UTC)", | ||
currentTimeOffsetInMinutes: 0, | ||
currentTimeFormat: "+00:00 Coordinated Universal Time (UTC)", | ||
}; |
{ | ||
"name": "@vvo/tzdb", | ||
"version": "6.5.1", | ||
"version": "6.6.0", | ||
"description": "Always up to date list of time zones, with grouping and major cities", | ||
@@ -97,4 +97,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/cli": "7.13.10", | ||
"@babel/core": "7.13.13", | ||
"@babel/cli": "7.13.14", | ||
"@babel/core": "7.13.14", | ||
"@babel/node": "7.13.13", | ||
@@ -101,0 +101,0 @@ "@babel/preset-env": "7.13.12", |
Sorry, the diff of this file is not supported yet
145371
1303