@vvo/tzdb 6.198.0 → 6.199.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,143 @@
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
+ Time zones for building a time zone picker, always up to date.
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
+ ```
11
+
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
+ - No dependencies, ESM and CommonJS, TypeScript types, 16 kB gzipped.
9
18
 
10
- The data and npm packages are **automatically updated** whenever there are changes to https://www.geonames.org/ which is generated from IANA databases.
19
+ ## Always up to date
11
20
 
12
- This is useful whenever you want to build a time zone select menu in your application.
21
+ Every day, a [GitHub workflow](.github/workflows/release.yml) compiles the latest
22
+ [IANA tz database](https://data.iana.org/time-zones/tzdb/), takes city populations from
23
+ [GeoNames](https://www.geonames.org/), tests the result and publishes a new version when something
24
+ changed.
13
25
 
14
- ## NPM package
26
+ Current offsets come from the browser or Node.js at runtime. A site that never updates this package
27
+ still follows daylight saving changes, and agrees with the offsets `Intl.DateTimeFormat` gives the
28
+ rest of the app.
15
29
 
16
- Installation:
30
+ ## Time zone picker
17
31
 
18
32
  ```bash
19
33
  npm add @vvo/tzdb
20
34
  ```
21
35
 
22
- Usage:
36
+ ```jsx
37
+ import { getTimeZones } from "@vvo/tzdb";
23
38
 
24
- ```js
25
- import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations } from "@vvo/tzdb";
39
+ const timeZones = getTimeZones();
40
+
41
+ // Saved values can be any IANA name, like "Asia/Calcutta" or "US/Pacific"
42
+ function findTimeZone(name) {
43
+ return timeZones.find((timeZone) => timeZone.group.includes(name));
44
+ }
45
+
46
+ function TimeZonePicker({ value, onChange }) {
47
+ const selected = findTimeZone(value ?? Intl.DateTimeFormat().resolvedOptions().timeZone);
48
+ return (
49
+ <select value={selected?.name} onChange={(event) => onChange(event.target.value)}>
50
+ {timeZones.map((timeZone) => (
51
+ <option key={timeZone.name} value={timeZone.name}>
52
+ {timeZone.currentTimeFormat}
53
+ </option>
54
+ ))}
55
+ </select>
56
+ );
57
+ }
26
58
  ```
27
59
 
28
- ## API
60
+ Save `name` in the database: every `Intl` API and date library accepts it.
29
61
 
30
- ### getTimeZones()
62
+ To search, match the query against the fields people type:
31
63
 
32
64
  ```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 });
65
+ timeZones.filter((timeZone) =>
66
+ [timeZone.currentTimeFormat, timeZone.countryName, timeZone.abbreviation, ...timeZone.group]
67
+ .join(" ")
68
+ .toLowerCase()
69
+ .includes(query.toLowerCase()),
70
+ );
38
71
  ```
39
72
 
40
- This method returns an array of time zones objects:
73
+ ## API
41
74
 
42
75
  ```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
- ];
76
+ import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations, tzdbVersion } from "@vvo/tzdb";
62
77
  ```
63
78
 
64
- When relevant, time zones are grouped. The rules for grouping are:
65
-
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
79
+ ### getTimeZones(options)
71
80
 
72
- Here's a grouping example:
81
+ Returns time zones sorted by current offset:
73
82
 
74
83
  ```js
75
84
  {
76
- name: "America/Dawson_Creek",
77
- alternativeName: "Mountain Time",
78
- group: ["America/Creston", "America/Dawson_Creek", "America/Fort_Nelson"],
85
+ name: "America/Los_Angeles",
86
+ alternativeName: "Pacific Time",
87
+ group: ["America/Los_Angeles", "US/Pacific", "PST8PDT"],
79
88
  continentCode: "NA",
80
89
  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",
90
+ countryName: "United States",
91
+ countryCode: "US",
92
+ mainCities: ["Los Angeles", "San Diego", "San Jose", "San Francisco"],
93
+ rawOffsetInMinutes: -480,
94
+ abbreviation: "PST",
95
+ dstAbbreviation: "PDT", // only for zones with daylight saving time
96
+ rawFormat: "-08:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
87
97
  currentTimeOffsetInMinutes: -420,
88
- currentTimeFormat: "-07:00 Mountain Time - Fort St. John, Creston"
98
+ currentTimeFormat: "-07:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
99
+ currentAbbreviation: "PDT",
89
100
  }
90
101
  ```
91
102
 
92
- ### rawTimeZones
103
+ Options:
93
104
 
94
- This is an array of time zone objects without the current time information:
105
+ - `locale`: translates `alternativeName`, `countryName` and `continentName`. With `"fr"`, Los Angeles
106
+ shows as "-07:00 heure du Pacifique nord-américain - Los Angeles, ...". City names stay as they are.
107
+ - `includeUtc`: adds `Etc/UTC`, whose group includes `UTC` and `GMT`.
108
+ - `includeGmtOffsets`: adds the fixed offsets `Etc/GMT-14` to `Etc/GMT+12`. As in POSIX, the sign
109
+ is inverted: `Etc/GMT+5` is 5 hours behind UTC.
95
110
 
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
- ```
111
+ Zones the browser does not know yet are left out, since `Intl` could not format dates in them.
112
+ Runtimes without `Intl` time zone support get every zone at its standard offset.
115
113
 
116
- ### timeZonesNames
114
+ ### rawTimeZones
117
115
 
118
- This is an array of time zone names:
116
+ The same list without the `current*` fields, sorted by standard offset.
119
117
 
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
- ```
118
+ ### timeZonesNames
119
+
120
+ Every IANA time zone name from [zone.tab](https://data.iana.org/time-zones/tzdb/zone.tab).
140
121
 
141
122
  ### abbreviations
142
123
 
143
- This is an object mapping timezone abbreviations to their full forms:
124
+ Long names mapped to abbreviations, like `"Central European Summer Time": "CEST"`. Careful, CST
125
+ means Central Standard Time (-06:00), China Standard Time (+08:00) and Cuba Standard Time (-05:00).
144
126
 
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
- ```
127
+ ### tzdbVersion
167
128
 
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()`.
129
+ The IANA tz database release behind the data, like `"2026e"`.
169
130
 
170
- ## Notes
131
+ ## How time zones are grouped
171
132
 
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:
133
+ Zones share an entry when they are in the same country and their clocks show the same time for the
134
+ next two years. Detroit and New York had different rules a century ago, so IANA keeps both, but
135
+ they share an entry today.
177
136
 
178
- ```js
179
- const value = timeZones.find((timeZone) => {
180
- return dbData.timeZone === timeZone.name || timeZone.group.includes(dbData.timeZone);
181
- });
182
- ```
137
+ `alternativeName` is the English name from [CLDR](https://cldr.unicode.org/) without "Standard",
138
+ "Daylight" or "Summer". When summer and winter names differ, like "Greenwich Mean Time" and "British
139
+ Summer Time", it is CLDR's generic name, "United Kingdom Time". Several countries share names like
140
+ "Eastern Time", so show `countryName` or `mainCities` next to it.
141
+
142
+ Abbreviations come from IANA. When IANA has none, like "+03", they come from `abbreviations` or
143
+ 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",