@vvo/tzdb 6.198.0 → 6.200.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,182 +1,183 @@
1
- # tzdb [![GitHub license](https://img.shields.io/github/license/vvo/tzdb?style=flat)](https://github.com/vvo/tzdb/blob/main/LICENSE) [![Tests](https://github.com/vvo/tzdb/workflows/CI/badge.svg)](https://github.com/vvo/tzdb/actions) [![npm version](https://badge.fury.io/js/%40vvo%2Ftzdb.svg)](https://www.npmjs.com/package/@vvo/tzdb) [![minizipped size](https://badgen.net/bundlephobia/minzip/@vvo/tzdb@latest)](https://bundlephobia.com/result?p=@vvo/tzdb@latest)
1
+ # tzdb [![npm version](https://badge.fury.io/js/%40vvo%2Ftzdb.svg)](https://www.npmjs.com/package/@vvo/tzdb)
2
2
 
3
- This is a list and npm package of:
3
+ Always up to date time zones for time zone pickers, and the country of any time zone.
4
4
 
5
- - "simplified" [IANA time zones](https://www.iana.org/time-zones) with their alternative names like `Pacific Time` instead of `America/Los_Angeles`, along with major cities for each time zone.
6
- - all existing raw IANA time zones names
7
- - "raw" offsets along with current time offsets
8
- - also includes [deprecated time zone names](https://data.iana.org/time-zones/data/backward) for compatibility
5
+ ```js
6
+ import { getTimeZones } from "@vvo/tzdb";
7
+
8
+ getTimeZones().map((timeZone) => timeZone.currentTimeFormat);
9
+ // [..., "-07:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco", ...]
10
+ ```
9
11
 
10
- The data and npm packages are **automatically updated** whenever there are changes to https://www.geonames.org/ which is generated from IANA databases.
12
+ - Every [IANA time zone](https://www.iana.org/time-zones), grouped by country and clock, with major
13
+ cities.
14
+ - Current offsets and abbreviations: PDT in summer, PST in winter.
15
+ - Every current and deprecated IANA name, so saved values always find their entry.
16
+ - Names in any language the browser supports.
17
+ - The country of a visitor's time zone, to guess where they are without an IP lookup.
18
+ - No dependencies, ESM and CommonJS, TypeScript types.
11
19
 
12
- This is useful whenever you want to build a time zone select menu in your application.
20
+ ## Always up to date
13
21
 
14
- ## NPM package
22
+ Every day, a [GitHub workflow](.github/workflows/release.yml) compiles the latest
23
+ [IANA tz database](https://data.iana.org/time-zones/tzdb/), takes city populations from
24
+ [GeoNames](https://www.geonames.org/), tests the result and publishes a new version when something
25
+ changed.
15
26
 
16
- Installation:
27
+ Current offsets come from the browser or Node.js at runtime. A site that never updates this package
28
+ still follows daylight saving changes, and agrees with the offsets `Intl.DateTimeFormat` gives the
29
+ rest of the app.
30
+
31
+ ## Time zone picker
17
32
 
18
33
  ```bash
19
34
  npm add @vvo/tzdb
20
35
  ```
21
36
 
22
- Usage:
37
+ ```jsx
38
+ import { getTimeZones } from "@vvo/tzdb";
23
39
 
24
- ```js
25
- import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations } from "@vvo/tzdb";
40
+ const timeZones = getTimeZones();
41
+
42
+ // Saved values can be any IANA name, like "Asia/Calcutta" or "US/Pacific"
43
+ function findTimeZone(name) {
44
+ return timeZones.find((timeZone) => timeZone.group.includes(name));
45
+ }
46
+
47
+ function TimeZonePicker({ value, onChange }) {
48
+ const selected = findTimeZone(value ?? Intl.DateTimeFormat().resolvedOptions().timeZone);
49
+ return (
50
+ <select value={selected?.name} onChange={(event) => onChange(event.target.value)}>
51
+ {timeZones.map((timeZone) => (
52
+ <option key={timeZone.name} value={timeZone.name}>
53
+ {timeZone.currentTimeFormat}
54
+ </option>
55
+ ))}
56
+ </select>
57
+ );
58
+ }
26
59
  ```
27
60
 
28
- ## API
61
+ Save `name` in the database: every `Intl` API and date library accepts it.
29
62
 
30
- ### getTimeZones()
63
+ To search, match the query against the fields people type:
31
64
 
32
65
  ```js
33
- const timeZones = getTimeZones();
34
-
35
- // You can also provide an optional parameter to include UTC in the result.
36
- // This adds a time zone with the name "UTC" and a fixed offset of 0.
37
- const timeZonesWithUtc = getTimeZones({ includeUtc: true });
66
+ timeZones.filter((timeZone) =>
67
+ [timeZone.currentTimeFormat, timeZone.countryName, timeZone.abbreviation, ...timeZone.group]
68
+ .join(" ")
69
+ .toLowerCase()
70
+ .includes(query.toLowerCase()),
71
+ );
38
72
  ```
39
73
 
40
- This method returns an array of time zones objects:
74
+ ## Country of a visitor
41
75
 
42
76
  ```js
43
- [
44
- // ...
45
- {
46
- name: "America/Los_Angeles",
47
- alternativeName: "Pacific Time",
48
- group: ["America/Los_Angeles"],
49
- continentCode: "NA",
50
- continentName: "North America",
51
- countryName: "United States",
52
- countryCode: "US",
53
- mainCities: ["Los Angeles", "San Diego", "San Jose", "San Francisco"],
54
- rawOffsetInMinutes: -480,
55
- abbreviation: "PST",
56
- rawFormat: "-08:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
57
- currentTimeOffsetInMinutes: -420, // "current" time zone offset, this is why getTimeZones() is a method and not just an object: it works at runtime
58
- currentTimeFormat: "-07:00 Pacific Time - Los Angeles, San Diego",
59
- },
60
- // ...
61
- ];
77
+ import { getCountryCode } from "@vvo/tzdb";
78
+
79
+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; // "Europe/Paris"
80
+ getCountryCode(timeZone); // "FR"
81
+ new Intl.DisplayNames(["en"], { type: "region" }).of("FR"); // "France"
62
82
  ```
63
83
 
64
- When relevant, time zones are grouped. The rules for grouping are:
84
+ It knows every IANA name, including old ones browsers still return, like `Asia/Calcutta`. It weighs
85
+ 4 kB and does not load the time zone list.
86
+
87
+ ## API
65
88
 
66
- - if the time zones are in the same country
67
- - if the DST or summer time offsets are the same
68
- - if the non-DST, non-summer time offsets are the same
69
- - then we group the time zones
70
- - the "main" time zone name (`name` attribute), is always the one from the most populated city
89
+ ```js
90
+ import {
91
+ getTimeZones,
92
+ getCountryCode,
93
+ rawTimeZones,
94
+ timeZonesNames,
95
+ abbreviations,
96
+ tzdbVersion,
97
+ } from "@vvo/tzdb";
98
+ ```
71
99
 
72
- Here's a grouping example:
100
+ ### getTimeZones(options)
101
+
102
+ Returns time zones sorted by current offset:
73
103
 
74
104
  ```js
75
105
  {
76
- name: "America/Dawson_Creek",
77
- alternativeName: "Mountain Time",
78
- group: ["America/Creston", "America/Dawson_Creek", "America/Fort_Nelson"],
106
+ name: "America/Los_Angeles",
107
+ alternativeName: "Pacific Time",
108
+ group: ["America/Los_Angeles", "US/Pacific", "PST8PDT"],
79
109
  continentCode: "NA",
80
110
  continentName: "North America",
81
- countryName: "Canada",
82
- countryCode: "CA",
83
- mainCities: ["Fort St. John", "Creston", "Fort Nelson"],
84
- rawOffsetInMinutes: -420,
85
- abbreviation: "MST",
86
- rawFormat: "-07:00 Mountain Time - Fort St. John, Creston, Fort Nelson",
111
+ countryName: "United States",
112
+ countryCode: "US",
113
+ mainCities: ["Los Angeles", "San Diego", "San Jose", "San Francisco"],
114
+ rawOffsetInMinutes: -480,
115
+ abbreviation: "PST",
116
+ dstAbbreviation: "PDT", // only for zones with daylight saving time
117
+ rawFormat: "-08:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
87
118
  currentTimeOffsetInMinutes: -420,
88
- currentTimeFormat: "-07:00 Mountain Time - Fort St. John, Creston"
119
+ currentTimeFormat: "-07:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
120
+ currentAbbreviation: "PDT",
89
121
  }
90
122
  ```
91
123
 
92
- ### rawTimeZones
124
+ Options:
93
125
 
94
- This is an array of time zone objects without the current time information:
126
+ - `locale`: translates `alternativeName`, `countryName` and `continentName`. With `"fr"`, Los Angeles
127
+ shows as "-07:00 heure du Pacifique nord-américain - Los Angeles, ...". City names stay as they are.
128
+ - `includeUtc`: adds `Etc/UTC`, whose group includes `UTC` and `GMT`.
129
+ - `includeGmtOffsets`: adds the fixed offsets `Etc/GMT-14` to `Etc/GMT+12`. As in POSIX, the sign
130
+ is inverted: `Etc/GMT+5` is 5 hours behind UTC.
95
131
 
96
- ```js
97
- [
98
- // ...
99
- {
100
- name: "America/Los_Angeles",
101
- alternativeName: "Pacific Time",
102
- group: ["America/Los_Angeles"],
103
- continentCode: "NA",
104
- continentName: "North America",
105
- countryName: "United States",
106
- countryCode: "US",
107
- mainCities: ["Los Angeles", "San Diego", "San Jose", "San Francisco"],
108
- rawOffsetInMinutes: -480,
109
- abbreviation: "PST",
110
- rawFormat: "-08:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
111
- },
112
- // ...
113
- ];
114
- ```
132
+ Zones the browser does not know yet are left out, since `Intl` could not format dates in them.
133
+ Runtimes without `Intl` time zone support get every zone at its standard offset.
115
134
 
116
- ### timeZonesNames
135
+ ### getCountryCode(timeZone)
117
136
 
118
- This is an array of time zone names:
137
+ The [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code of an IANA time zone
138
+ name, or `undefined` for names without a country like `UTC`.
119
139
 
120
- ```js
121
- [
122
- // ...
123
- "America/Juneau",
124
- "America/Kentucky/Louisville",
125
- "America/Kentucky/Monticello",
126
- "America/Kralendijk",
127
- "America/La_Paz",
128
- "America/Lima",
129
- "America/Los_Angeles",
130
- "America/Lower_Princes",
131
- "America/Maceio",
132
- "America/Managua",
133
- "America/Manaus",
134
- "America/Marigot",
135
- "America/Martinique",
136
- "America/Matamoros",
137
- // ...
138
- ];
139
- ```
140
+ ### rawTimeZones
141
+
142
+ The same list without the `current*` fields, sorted by standard offset.
143
+
144
+ ### timeZonesNames
145
+
146
+ Every IANA time zone name from [zone.tab](https://data.iana.org/time-zones/tzdb/zone.tab).
140
147
 
141
148
  ### abbreviations
142
149
 
143
- This is an object mapping timezone abbreviations to their full forms:
150
+ Long names mapped to abbreviations, like `"Central European Summer Time": "CEST"`. Careful, CST
151
+ means Central Standard Time (-06:00), China Standard Time (+08:00) and Cuba Standard Time (-05:00).
144
152
 
145
- ```js
146
- {
147
- // ...
148
- "Australian Central Daylight Time": "ACDT",
149
- "Australian Central Standard Time": "ACST",
150
- "Australian Central Time": "ACT",
151
- "Australian Central Western Standard Time": "ACWST",
152
- "Australian Eastern Daylight Time": "AEDT",
153
- "Australian Eastern Standard Time": "AEST",
154
- "Australian Eastern Time": "AET",
155
- "Australian Western Daylight Time": "AWDT",
156
- "Australian Western Standard Time": "AWST",
157
- "Azerbaijan Summer Time": "AZST",
158
- "Azerbaijan Time": "AZT",
159
- "Azores Summer Time": "AZOST",
160
- "Azores Time": "AZOT",
161
- "Bangladesh Standard Time": "BST",
162
- "Bhutan Time": "BTT",
163
- "Bolivia Time": "BOT",
164
- // ...
165
- };
166
- ```
153
+ ### tzdbVersion
167
154
 
168
- **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()`.
155
+ The IANA tz database release behind the data, like `"2026e"`.
169
156
 
170
- ## Notes
157
+ ## Compared to countries-and-timezones
171
158
 
172
- - We provide two cities when grouping happens, ranked by population
173
- - We provide alternative names ("Pacific Time" for "America/Los_Angeles") and remove "Standard", "Daylight" or "Summer" from them
174
- - If you're using this to build a time zone selector and saving to a database then:
175
- - make sure to save the `name` attribute (`America/Los_Angeles`) in your database
176
- - when displaying the select with a default value from your database, either select the time zone name that matches, or if the time zone name is part of the group. Example:
159
+ | | @vvo/tzdb | countries-and-timezones |
160
+ | ---------------------------------- | ---------------------------- | ----------------------------------- |
161
+ | Data updates | Every day, automatically | By hand |
162
+ | Current offsets | From the browser, at runtime | Computed when the package was built |
163
+ | Grouped list with cities and names | Yes | No |
164
+ | Abbreviations that follow DST | Yes | No |
165
+ | Translations | Any language the browser has | No |
166
+ | Country of a time zone | 4 kB | 9 kB |
167
+ | Everything | 17 kB | 9 kB |
177
168
 
178
- ```js
179
- const value = timeZones.find((timeZone) => {
180
- return dbData.timeZone === timeZone.name || timeZone.group.includes(dbData.timeZone);
181
- });
182
- ```
169
+ Sizes are minified and gzipped.
170
+
171
+ ## How time zones are grouped
172
+
173
+ Zones share an entry when they are in the same country and their clocks show the same time for the
174
+ next two years. Detroit and New York had different rules a century ago, so IANA keeps both, but
175
+ they share an entry today.
176
+
177
+ `alternativeName` is the English name from [CLDR](https://cldr.unicode.org/) without "Standard",
178
+ "Daylight" or "Summer". When summer and winter names differ, like "Greenwich Mean Time" and "British
179
+ Summer Time", it is CLDR's generic name, "United Kingdom Time". Several countries share names like
180
+ "Eastern Time", so show `countryName` or `mainCities` next to it.
181
+
182
+ Abbreviations come from IANA. When IANA has none, like "+03", they come from `abbreviations` or
183
+ read "GMT+3".
@@ -44,6 +44,7 @@
44
44
  "Bravo Time Zone": "B",
45
45
  "British Summer Time": "BST",
46
46
  "Brunei Darussalam Time": "BNT",
47
+ "Brunei Time": "BNT",
47
48
  "Cape Verde Time": "CVT",
48
49
  "Casey Time": "CAST",
49
50
  "Cayman Islands Daylight Saving Time": "CIDST",
@@ -58,8 +59,10 @@
58
59
  "Central Time": "CT",
59
60
  "Chamorro Standard Time": "ChST",
60
61
  "Charlie Time Zone": "C",
62
+ "Chatham Daylight Time": "CHADT",
61
63
  "Chatham Island Daylight Time": "CHADT",
62
64
  "Chatham Island Standard Time": "CHAST",
65
+ "Chatham Standard Time": "CHAST",
63
66
  "Chatham Time": "CHAST",
64
67
  "Chile Standard Time": "CLT",
65
68
  "Chile Summer Time": "CLST",
@@ -77,6 +80,7 @@
77
80
  "Cuba Standard Time": "CST",
78
81
  "Davis Time": "DAVT",
79
82
  "Delta Time Zone": "D",
83
+ "Dumont d’Urville Time": "DDUT",
80
84
  "Dumont-d'Urville Time": "DDUT",
81
85
  "Dumont-d’Urville Time": "DDUT",
82
86
  "East Africa Time": "EAT",
@@ -113,6 +117,8 @@
113
117
  "Gilbert Island Time": "GILT",
114
118
  "Gilbert Islands Time": "GILT",
115
119
  "Golf Time Zone": "G",
120
+ "Greenland Standard Time": "WGT",
121
+ "Greenland Summer Time": "WGST",
116
122
  "Greenwich Mean Time": "GMT",
117
123
  "Gulf Standard Time": "GST",
118
124
  "Guyana Time": "GYT",
@@ -138,6 +144,8 @@
138
144
  "Japan Standard Time": "JST",
139
145
  "Kamchatka Summer Time": "PETST",
140
146
  "Kamchatka Time": "PETT",
147
+ "Khovd Standard Time": "HOVT",
148
+ "Khovd Summer Time": "HOVST",
141
149
  "Kilo Time Zone": "K",
142
150
  "Korea Standard Time": "KST",
143
151
  "Korean Time": "KST",
@@ -174,6 +182,8 @@
174
182
  "Newfoundland Standard Time": "NST",
175
183
  "Niue Time": "NUT",
176
184
  "Norfolk Daylight Time": "NFDT",
185
+ "Norfolk Island Daylight Time": "NFDT",
186
+ "Norfolk Island Standard Time": "NFT",
177
187
  "Norfolk Island Time": "NFT",
178
188
  "Norfolk Time": "NFT",
179
189
  "November Time Zone": "N",
@@ -218,6 +228,8 @@
218
228
  "South Africa Standard Time": "SAST",
219
229
  "South Georgia Time": "GST",
220
230
  "Srednekolymsk Time": "SRET",
231
+ "St. Pierre & Miquelon Daylight Time": "PMDT",
232
+ "St. Pierre & Miquelon Standard Time": "PMST",
221
233
  "St. Pierre & Miquelon Time": "PM",
222
234
  "Suriname Time": "SRT",
223
235
  "Syowa Time": "SYOT",
@@ -225,12 +237,15 @@
225
237
  "Taipei Time": "TWT",
226
238
  "Tajikistan Time": "TJT",
227
239
  "Tango Time Zone": "T",
240
+ "Timor-Leste Time": "TLT",
228
241
  "Tokelau Time": "TKT",
229
242
  "Tonga Summer Time": "TOST",
230
243
  "Tonga Time": "TOT",
231
244
  "Turkey Time": "TRT",
232
245
  "Turkmenistan Time": "TMT",
233
246
  "Tuvalu Time": "TVT",
247
+ "Türkiye Standard Time": "TRT",
248
+ "Türkiye Time": "TRT",
234
249
  "Ulaanbaatar Summer Time": "ULAST",
235
250
  "Ulaanbaatar Time": "ULAT",
236
251
  "Uniform Time Zone": "U",