How to use the @phensley/timezone.TZ.zoneIds function in @phensley/timezone

To help you get started, we’ve selected a few @phensley/timezone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phensley / cldr-engine / packages / cldr-core / src / systems / calendars / timezone.ts View on Github external
const index = numarray(raw.index, 36);
    const offsets = numarray(raw.offsets, 36);
    const untils = numarray(raw.untils, 36).map(n => n === -1 ? n : n * 1000);

    for (let i = 0; i < index.length; i += 2) {
      const s = index[i];
      const e = index[i + 1];
      const rec = {
        offsets: offsets.slice(s, e),
        untils: untils.slice(s, e)
      };
      this.metazones.push(rec);
    }

    // mapping of zoneid to metazone records
    const zoneids = TZ.zoneIds();
    const zoneindex = numarray(raw.zoneindex, 36);

    // Mapping of tzdb id back to cldr stable id used for schema lookups
    raw.stableids.split('|').forEach((d: string) => {
      const p = d.split(':');
      const i = Number(p[0]);
      this.stableids.set(zoneids[i], p[1]);
    });

    // Sanity-check, since the zoneindex is based off the canonical
    // zoneids array, but could be generated at different times. our test
    // cases should ensure they're in sync, but warn of a discrepancy
    /* istanbul ignore if */
    if (zoneids.length !== zoneindex.length) {
      console.log(`Error: time zone ids and zone index are not in sync!`);
    }
github phensley / cldr-engine / packages / cldr-compiler / src / cli / generator / code / aliases.ts View on Github external
const result: Code[] = [];

  let code = HEADER + NOLINT_MAXLINE;
  code += `export const languageAliasRaw = '${languages}';\n\n`;
  code += `export const scriptAliasRaw = '${scripts}';\n`;

  result.push(Code.locale(['autogen.aliases.ts'], code));

  code = HEADER + NOLINT_MAXLINE;
  code += `export const territoryAliasRaw = '${territories}';\n`;

  result.push(Code.languagetag(['autogen.aliases.ts'], code));

  // Find time zone aliases that are not already handled in the @phensley/timezone package
  const zoneids = TZ.zoneIds();
  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('|');

  code = HEADER + NOLINT_MAXLINE;
  code += `export const zoneAliasRaw = '${zones}';\n`;

  result.push(Code.core(['systems', 'calendars', 'autogen.aliases.ts'], code));
github phensley / cldr-engine / packages / cldr-compiler / src / cli / generator / code / zones.ts View on Github external
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('|');
};
github phensley / cldr-engine / packages / cldr-compiler / src / cli / generator / code / zones.ts View on Github external
const buildMetaZones2 = (data: any): Metazones => {
  const metazoneIndex = new IdArray();

  const offsets: number[] = [];
  const untils: number[] = [];
  const index: number[] = [];

  const zonemap = new Map();

  // Array of canonical time zone ids
  const zoneids = TZ.zoneIds();

  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);
  });

@phensley/timezone

Compact timezone lib based on tz database

Apache-2.0
Latest version published 17 days ago

Package Health Score

60 / 100
Full package analysis