@vvo/tzdb 6.199.0 → 6.201.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,6 +1,6 @@
1
1
  # tzdb [![npm version](https://badge.fury.io/js/%40vvo%2Ftzdb.svg)](https://www.npmjs.com/package/@vvo/tzdb)
2
2
 
3
- Time zones for building a time zone picker, always up to date.
3
+ Always up to date time zones for time zone pickers, and the country of any time zone.
4
4
 
5
5
  ```js
6
6
  import { getTimeZones } from "@vvo/tzdb";
@@ -14,7 +14,8 @@ getTimeZones().map((timeZone) => timeZone.currentTimeFormat);
14
14
  - Current offsets and abbreviations: PDT in summer, PST in winter.
15
15
  - Every current and deprecated IANA name, so saved values always find their entry.
16
16
  - Names in any language the browser supports.
17
- - No dependencies, ESM and CommonJS, TypeScript types, 16 kB gzipped.
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.
18
19
 
19
20
  ## Always up to date
20
21
 
@@ -70,10 +71,30 @@ timeZones.filter((timeZone) =>
70
71
  );
71
72
  ```
72
73
 
74
+ ## Country of a visitor
75
+
76
+ ```js
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"
82
+ ```
83
+
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
+
73
87
  ## API
74
88
 
75
89
  ```js
76
- import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations, tzdbVersion } from "@vvo/tzdb";
90
+ import {
91
+ getTimeZones,
92
+ getCountryCode,
93
+ rawTimeZones,
94
+ timeZonesNames,
95
+ abbreviations,
96
+ tzdbVersion,
97
+ } from "@vvo/tzdb";
77
98
  ```
78
99
 
79
100
  ### getTimeZones(options)
@@ -105,12 +126,18 @@ Options:
105
126
  - `locale`: translates `alternativeName`, `countryName` and `continentName`. With `"fr"`, Los Angeles
106
127
  shows as "-07:00 heure du Pacifique nord-américain - Los Angeles, ...". City names stay as they are.
107
128
  - `includeUtc`: adds `Etc/UTC`, whose group includes `UTC` and `GMT`.
129
+ - `date`: computes the `current*` fields at this date instead of now, like the date of a meeting.
108
130
  - `includeGmtOffsets`: adds the fixed offsets `Etc/GMT-14` to `Etc/GMT+12`. As in POSIX, the sign
109
131
  is inverted: `Etc/GMT+5` is 5 hours behind UTC.
110
132
 
111
133
  Zones the browser does not know yet are left out, since `Intl` could not format dates in them.
112
134
  Runtimes without `Intl` time zone support get every zone at its standard offset.
113
135
 
136
+ ### getCountryCode(timeZone)
137
+
138
+ The [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code of an IANA time zone
139
+ name, or `undefined` for names without a country like `UTC`.
140
+
114
141
  ### rawTimeZones
115
142
 
116
143
  The same list without the `current*` fields, sorted by standard offset.
@@ -128,6 +155,20 @@ means Central Standard Time (-06:00), China Standard Time (+08:00) and Cuba Stan
128
155
 
129
156
  The IANA tz database release behind the data, like `"2026e"`.
130
157
 
158
+ ## Compared to countries-and-timezones
159
+
160
+ | | @vvo/tzdb | countries-and-timezones |
161
+ | --------------------------------- | ---------------------------- | ----------------------------------- |
162
+ | Data updates | Every day, automatically | By hand |
163
+ | Current offsets | From the browser, at runtime | Computed when the package was built |
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
+ | Picker list with cities and names | 17 kB | Not available |
168
+
169
+ Sizes are minified and gzipped. countries-and-timezones weighs 9 kB in total, without cities, display
170
+ names or abbreviations.
171
+
131
172
  ## How time zones are grouped
132
173
 
133
174
  Zones share an entry when they are in the same country and their clocks show the same time for the