@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 +97 -136
- package/abbreviations.json +15 -0
- package/dist/index.cjs +992 -0
- package/dist/index.d.cts +54 -0
- package/dist/index.d.ts +51 -25
- package/dist/index.js +964 -30
- package/package.json +35 -96
- package/raw-time-zones.json +166 -167
- package/time-zones-names.json +1 -1
- package/dist/formatTimeZone.js +0 -26
- package/dist/formatTimeZone.js.map +0 -1
- package/dist/getTimeZones.js +0 -62
- package/dist/getTimeZones.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/timeZone.js +0 -99
- package/dist/utils/timeZone.js.map +0 -1
- package/index.d.ts +0 -28
- package/lib/formatTimeZone.js +0 -31
- package/lib/getTimeZones.js +0 -71
- package/lib/index.js +0 -4
- package/lib/utils/timeZone.js +0 -113
package/README.md
CHANGED
|
@@ -1,182 +1,143 @@
|
|
|
1
|
-
# tzdb [](https://www.npmjs.com/package/@vvo/tzdb)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Time zones for building a time zone picker, always up to date.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
19
|
+
## Always up to date
|
|
11
20
|
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
+
## Time zone picker
|
|
17
31
|
|
|
18
32
|
```bash
|
|
19
33
|
npm add @vvo/tzdb
|
|
20
34
|
```
|
|
21
35
|
|
|
22
|
-
|
|
36
|
+
```jsx
|
|
37
|
+
import { getTimeZones } from "@vvo/tzdb";
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
60
|
+
Save `name` in the database: every `Intl` API and date library accepts it.
|
|
29
61
|
|
|
30
|
-
|
|
62
|
+
To search, match the query against the fields people type:
|
|
31
63
|
|
|
32
64
|
```js
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
+
Returns time zones sorted by current offset:
|
|
73
82
|
|
|
74
83
|
```js
|
|
75
84
|
{
|
|
76
|
-
name: "America/
|
|
77
|
-
alternativeName: "
|
|
78
|
-
group: ["America/
|
|
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: "
|
|
82
|
-
countryCode: "
|
|
83
|
-
mainCities: ["
|
|
84
|
-
rawOffsetInMinutes: -
|
|
85
|
-
abbreviation: "
|
|
86
|
-
|
|
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
|
|
98
|
+
currentTimeFormat: "-07:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
|
|
99
|
+
currentAbbreviation: "PDT",
|
|
89
100
|
}
|
|
90
101
|
```
|
|
91
102
|
|
|
92
|
-
|
|
103
|
+
Options:
|
|
93
104
|
|
|
94
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
114
|
+
### rawTimeZones
|
|
117
115
|
|
|
118
|
-
|
|
116
|
+
The same list without the `current*` fields, sorted by standard offset.
|
|
119
117
|
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
129
|
+
The IANA tz database release behind the data, like `"2026e"`.
|
|
169
130
|
|
|
170
|
-
##
|
|
131
|
+
## How time zones are grouped
|
|
171
132
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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".
|
package/abbreviations.json
CHANGED
|
@@ -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",
|