Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getStableTimeZoneId = (zoneid: string): string => {
init();
// Check if this is already a CLDR stable timezone id.
const isstable = TimeZoneStableIdIndex.get(zoneid) !== -1;
if (!isstable) {
// Resolve the passed-in string to a real tzdb zone id
const realid = TZ.resolveId(zoneid);
if (realid) {
// Map to a CLDR stable id
zoneid = metazones!.getStableId(realid);
}
}
return zoneid;
};
const buildStableIdMapping = (data: any): string => {
const tzids = TZ.zoneIds();
const stableids = data.timeZoneIds;
const res: string[] = [];
for (const stableid of stableids) {
const resolved = TZ.resolveId(stableid);
if (resolved === undefined || stableid === resolved) {
continue;
}
const i = tzids.indexOf(resolved);
// const j = stableids.indexOf(stableid);
res.push(`${i}:${stableid}`);
}
return res.join('|');
};
Object.keys(data).forEach((id, mi) => {
// Map the metazone id to the index of the time zone id in the TZ data.
let zi = zoneids.indexOf(id);
if (zi === -1) {
// We have an alias, e.g. Africa/Addis_Ababa, so follow the link to
// get the correct tzdb id.
const zid = TZ.resolveId(id);
if (zid === undefined) {
throw new Error(`${chalk.red('Error')} tzdb / cldr mismatch. zone id failed ${id}`);
}
zi = zoneids.indexOf(zid);
}
zonemap.set(zi, mi);
});
const zones = Object.keys(zoneAlias).filter(alias => {
const zi = zoneids.indexOf(alias);
if (zi !== -1) {
// alias is in list of valid tzdb ids, ignore
return false;
}
// if alias fails to resolve, include in this list
return TZ.resolveId(alias) === undefined;
}).sort().map(k => [k, zoneAlias[k]].join(':')).join('|');
resolveTimeZoneId(zoneid: string): string | undefined {
return TZ.resolveId(substituteZoneAlias(zoneid));
}