Skip to content

Commit 5bb71a6

Browse files
committed
docs: Describe the time zone data generator
1 parent 3945a5a commit 5bb71a6

5 files changed

Lines changed: 80 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
8383

8484
## Release History
8585

86-
* 2018-11-17 v1.7.0 Include full time zone data separately and data for years 1970-2038.
86+
* 2018-11-17 v1.8.0 Include time zone data for years 1970-2038.
87+
* 2018-11-17 v1.7.0 Include full time zone data separately loadable.
8788
* 2018-11-06 v1.6.0 Upgrade the time zone database to the version 2018g.
8889
* 2018-10-08 v1.5.5 Fix compatibility with IE. Thanks, [Andrii](https://github.com/AndriiDidkivsky)!
8990
* 2018-10-06 v1.5.0 Add TypeScript export declarations.

docs/API.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This library contains pure, immutable functions to query time zones, convert dat
2121
- [parseZonedTime](#parsezonedtime)
2222
- [populateTimeZones](#populatetimezones)
2323
- [setTimeZone](#settimezone)
24+
- [Data Generator](#data-generator)
2425

2526
## Loading
2627

@@ -49,7 +50,7 @@ Load the main module in the browser with plain JavaScript:
4950
</script>
5051
```
5152

52-
You can also load a specific version from CDN, for example: https://unpkg.com/timezone-support@1.6.0/dist/index.umd.js.
53+
You can also load a specific version from CDN, for example: https://unpkg.com/timezone-support@1.8.0/dist/index.umd.js.
5354

5455
## Modules
5556

@@ -428,7 +429,7 @@ const berlinTime = setTimeZone(date, berlin, { useUTC: true })
428429
// }
429430
```
430431

431-
`Date` objects in the last two scenarios are initialized only for formatting or conversion purposes, because other methods, than the date part getters, deliver wrong results. Such "invalid" `Date` instances should exist only temporarily in a restricted scope. They should not be shared widely in the application to prevent mistakes from happening. The local time in a valid `Date` object has to match the UTC time maintained by the same object.
432+
`Date` objects in the last two scenarios are initialized only for formatting or conversion purposes, because other methods, than the date part getters, deliver wrong results. Such "invalid" `Date` instances should exist only temporarily in a restricted scope. They should not be shared widely in the application to prevent mistakes from happening. The local time in a valid `Date` object has to match the UTC time maintained by the same object.
432433

433434
## Data Generator
434435

@@ -437,24 +438,26 @@ If you want to [limit the time zone data](#limit-the-loaded-time-zone-data) to i
437438
```txt
438439
Usage: create-timezone-data [options] <first year> <last year>
439440
441+
Generates time zone data for a selected year range.
442+
440443
Options:
441444
-V, --version output the version number
442445
-a, --all-years includes all available years
443446
-c, --as-cjs-module format the time zone data as a CommonJS module
444447
-d, --as-amd-module format the time zone data as an AMD module
445448
-m, --as-module format the time zone data as a JavaScript module
446-
-n, --umd-name UMD global export name, if not "timeZoneData"
449+
-n, --umd-name <name> UMD global export name, if not "timeZoneData"
447450
-o, --output-file <file> write the time zone data to a file
448451
-u, --as-umd-module format the time zone data as an UMD module
449452
-o, --output-file <file> write the time zone data to a file
450453
-h, --help output usage information
451454
452-
Time zone data are printed on the standard output as JSON by default.
455+
Time zone data are printed on the standard output as JSON by default.
453456
454-
Examples:
457+
Examples:
455458
456-
$ create-timezone-data 2012 2022
457-
$ create-timezone-data -m -o custom-data.js 1970 2038
459+
$ create-timezone-data 2012 2022
460+
$ create-timezone-data -m -o custom-data.js 1970 2038
458461
```
459462

460463
The module generated by this tool exposes a data object as a default export, which is expected bu the function[populatePluralData](#populatepluraldata).

docs/usage.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ Data for 2012-2022: 27 KB minified, 6.5 KB gzipped
183183
Custom time zone data can be used if the module `lookup-convert` is loaded instead of the default `index` module.
184184

185185
```html
186-
<script src="https://unpkg.com/timezone-support@1.6.0/dist/lookup-convert.umd.js"></script>
187-
<script src="https://unpkg.com/timezone-support@1.6.0/dist/data-2012-2022.umd.js"></script>
186+
<script src="https://unpkg.com/timezone-support@1.8.0/dist/lookup-convert.umd.js"></script>
187+
<script src="https://unpkg.com/timezone-support@1.8.0/dist/data-2012-2022.umd.js"></script>
188188
<script>
189189
(() => {
190190
const { populateTimeZones, findTimeZone, getZonedTime } = window['timezone-lookup-convert']
@@ -202,7 +202,7 @@ Custom time zone data can be used if the module `lookup-convert` is loaded inste
202202
If you want to use the time zone data for years 2012-2022 published by this project, you can simplify your code by using a bundled package with both data and code.
203203

204204
```html
205-
<script src="https://unpkg.com/timezone-support@1.6.0/dist/index-2012-2022.umd.js"></script>
205+
<script src="https://unpkg.com/timezone-support@1.8.0/dist/index-2012-2022.umd.js"></script>
206206
<script>
207207
(() => {
208208
const { findTimeZone, getZonedTime } = window['timezone-support']
@@ -236,4 +236,54 @@ See the function [populateTimeZones](./API.md#populatetimezones) for more inform
236236

237237
## Generate custom time zone data
238238

239+
Except for the time zone data for the three year spans bundled with this module, other data modules can be generated to customize the year span and thus the overall package size. There is a command line tool [`create-timezone-data`](./API.md#data-generator) for this included in this package.
240+
241+
For example, you can generate time zone data for years 1978-2028 and save it to the module `data-1978-2028.js` in the CommonJS format, which you wil bundle to your application:
242+
243+
```sh
244+
create-timezone-data -c -o custom-data-1978-2028.js 1978 2028
245+
```
246+
247+
And then load them instead of the default full time zone data. You need to require `timezone-support/dist/lookup-convert` instead of `timezone-support` everywhere in your application and populate the library with the custom data, when your application starts:
248+
249+
```js
250+
const { populateTimeZones } = require('timezone-support/dist/lookup-convert')
251+
const data = require('./data-1978-2028')
252+
253+
populateTimeZones(data)
254+
```
255+
256+
Let us have alook, how the same would work in an application loading their assets directly in the browser. You would generate a UMD module instead:
257+
258+
```sh
259+
create-timezone-data -u -o custom-data-1978-2028.js -n timeZoneData10782028 1978 2028
260+
```
261+
262+
And then load them at the beginning of a plain JavaScript application:
263+
264+
```html
265+
<script src="https://unpkg.com/timezone-support/dist/lookup-convert.umd.js"></script>
266+
<script src="./data-1978-2028.js"></script>
267+
<script>
268+
(() => {
269+
const { populateTimeZones } = window['timezone-lookup-convert']
270+
271+
populateTimeZones(window.timeZoneData10782028)
272+
})()
273+
</script>
274+
```
275+
276+
Or load it in an application using AMD modules:
277+
278+
```html
279+
<script src="https://unpkg.com/requirejs/require.js"></script>
280+
<script src="https://unpkg.com/timezone-support/dist/lookup-convert.umd.js"></script>
281+
<script src="./data-1978-2028.js"></script>
282+
<script>
283+
require(['timezone-lookup-convert', 'timeZoneData10782028'], function (tz, data) {
284+
tz.populateTimeZones(data)
285+
})()
286+
</script>
287+
```
288+
239289
[IANA time zone database]: https://www.iana.org/time-zones

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"email": "[email protected]",
88
"url": "http://prantl.tk"
99
},
10+
"contributors": [
11+
"CrisColamb <[email protected]>"
12+
],
1013
"license": "MIT",
1114
"licenses": [
1215
{

0 commit comments

Comments
 (0)