Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
raw-time-zones.json
time-zones-names.json
metadata.json
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/dist/
time-zones-names.json
raw-time-zones.json
metadata.json
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ npm add @vvo/tzdb
Usage:

```js
import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations } from "@vvo/tzdb";
import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations, metadata } from "@vvo/tzdb";
```

## API
Expand Down Expand Up @@ -167,6 +167,16 @@ This is an object mapping timezone abbreviations to their full forms:

**Caution:** Although abbreviations can be easy to lookup, they can be misleading. For example: CST can refer to Central Standard Time (-06.00 UTC), China Standard Time (+06.00 UTC) or Cuba Standard Time (-05.00 UTC). And abbreviation full forms don't directly map to any property in the time zone objects returned by `rawTimeZones` or `getTimeZones()`.

### metadata

This is an object containing metadata about the package:

```js
{
ianaTzVersion: "2025b", // The IANA time zone database version
}
```

## Notes

- We provide two cities when grouping happens, ranked by population
Expand Down
15 changes: 14 additions & 1 deletion generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import unzipper from "unzipper";
import got from "got";
import { DateTime } from "luxon";
import { orderBy, uniq } from "lodash";
import tzdata from "tzdata";
import * as tzdata from "tzdata";

import abbreviations from "./abbreviations.json";
import formatTimeZone from "./lib/formatTimeZone.js";
Expand All @@ -18,6 +18,14 @@ const timeZonesLinks = Object.entries(tzdata.zones).filter(([, value]) => {
});

async function run() {
// Validate time zone versions match
if (process.versions.tz !== tzdata.version) {
console.error(
`Time zone versions do not match\n Node tz version: ${process.versions.tz}\n tzdata version: ${tzdata.version}`,
);
process.exit(1);
}

const continents = {
AF: "Africa",
AS: "Asia",
Expand Down Expand Up @@ -312,6 +320,11 @@ async function run() {
]),
).replace(/},/g, "},\n"),
);

fs.writeFileSync(
path.join(__dirname, "metadata.json"),
JSON.stringify({ ianaTzVersion: tzdata.version }),
);
}

run().catch((error) => {
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ interface TimeZoneOptions {
includeUtc?: boolean;
}

interface Metadata {
ianaTzVersion: string;
}

export const rawTimeZones: RawTimeZone[];
export const timeZonesNames: TimeZoneName[];
export function getTimeZones(opts?: TimeZoneOptions): TimeZone[];
export const metadata: Metadata;
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as rawTimeZones } from "../raw-time-zones.json";
export { default as timeZonesNames } from "../time-zones-names.json";
export { default as getTimeZones } from "./getTimeZones.js";
export { default as abbreviations } from "../abbreviations.json";
export { default as metadata } from "../metadata.json";
1 change: 1 addition & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ianaTzVersion":"2025b"}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"time-zones-names.json",
"abbreviations.json",
"raw-time-zones.json",
"metadata.json",
"LICENSE",
"README.md",
"index.d.ts"
Expand Down Expand Up @@ -117,7 +118,7 @@
"semantic-release": "18.0.1",
"semantic-release-cli": "5.4.6",
"sort-keys": "4.2.0",
"tzdata": "1.0.45",
"tzdata": "1.0.46",
"unzipper": "0.12.3"
},
"publishConfig": {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.