Skip to content

Commit

Permalink
v5.4.0: add tzdata as a dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogier Schouten committed Nov 7, 2016
1 parent 1cc4ec4 commit be236ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
19 changes: 2 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Above all, it should give the same answers across platforms. At the time we star

## New in Version 5

The IANA time zone data is no longer included with this module. You need to install the 'tzdata' module (or one of the more light-weight tzdata-* modules) manually next to timezonecomplete.
The TZ data is now installed as a separate NPM module [tzdata](https://npmjs.com/package/tzdata). For browser use, the data is NOT automatically included anymore, to allow you to choose a subset of the data to optimize your bundle.

Separating the TZ data from timezonecomplete has three advantages:
1. The data becomes useful to other modules than just timezonecomplete
Expand All @@ -65,26 +65,11 @@ A small part of the external API had to change, but it only concerns parts you s

### Node.JS

You need to install both timezonecomplete and also one or more of the tzdata modules:

* [tzdata](https://npmjs.com/package/tzdata): contains all time zones. When in doubt, use this.
* [tzdata-africa](https://npmjs.com/package/tzdata-africa)
* [tzdata-antarctica](https://npmjs.com/package/tzdata-antarctica)
* [tzdata-asia](https://npmjs.com/package/tzdata-asia)
* [tzdata-australasia](https://npmjs.com/package/tzdata-australasia)
* [tzdata-backward](https://npmjs.com/package/tzdata-backward): contains deprecated zone names, depends on the other modules
* [tzdata-backward-utc](https://npmjs.com/package/tzdata-backward-utc): contains only the UTC and GMT zones of backward, depends on tzdata-etcetera
* [tzdata-etcetera](https://npmjs.com/package/tzdata-etcetera)
* [tzdata-europe](https://npmjs.com/package/tzdata-europe)
* [tzdata-northamerica](https://npmjs.com/package/tzdata-northamerica)
* [tzdata-pacificnew](https://npmjs.com/package/tzdata-pacificnew)
* [tzdata-southamerica](https://npmjs.com/package/tzdata-southamerica)
* [tzdata-systemv](https://npmjs.com/package/tzdata-systemv)
In Node.JS, timezonecomplete automatically has all time zone data.

Install using:
```
npm install timezonecomplete
npm install tzdata-northamerica tzdata-etcetera tzdata-backward-utc
```

Then require the timezonecomplete module in your code. Timezonecomplete will automatically find any installed tzdata modules:
Expand Down
7 changes: 7 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

# Changelog


## 5.4.0 (2016-11-07)

The tzdata module is not getting downloaded much and timezonecomplete is. This means that nobody understands that they have to install the tzdata manually. Therefore we make it automatic, assuming that for server use it doesn't matter to load all time zone data.

* Add the tzdata module as a proper dependency. For Node.JS applications, this will automatically add all time zones without initialisation. You can remove time zones by explicitly initializing the TzDatabase using TzDatabase.init().

## 5.3.0 (2016-11-07)

* Add DateTime#standardOffsetDuration() method that returns the offset excluding DST. (Issue #30)
Expand Down
45 changes: 31 additions & 14 deletions doc/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@

## Upgrading from version 4 to version 5

The TZ data is no longer installed with this module. You need to install the 'tzdata' module (or one of the more light-weight tzdata-* modules) manually next to timezonecomplete.
The TZ data is now installed as a separate NPM module [tzdata](https://npmjs.com/package/tzdata). Rather than using all time zones, you can also opt to install only a subset of zones by installing one or more of the smaller modules below and passing their data to TzDatabase.init().

Separating the TZ data from timezonecomplete has three advantages:

1. The data becomes useful to other modules than just timezonecomplete
1. By choosing for e.g. 'tzdata-northamerica', you can install just the time zones you need, which is especially handy for browser use (smaller footprint).
1. The upgrades to the TZ data become independent of changes to timezonecomplete. That means you do not have to upgrade to the latest timezonecomplete version to get the latest TZ data.

### Node.JS

Simply install one or more of the following NPM modules. Timezonecomplete will find any installed module on its own, you do not need to include them in your Node modules:

* [tzdata](https://npmjs.com/package/tzdata): contains all time zones. When in doubt, use this.
* [tzdata-africa](https://npmjs.com/package/tzdata-africa)
* [tzdata-antarctica](https://npmjs.com/package/tzdata-antarctica)
* [tzdata-asia](https://npmjs.com/package/tzdata-asia)
Expand All @@ -30,12 +19,40 @@ Simply install one or more of the following NPM modules. Timezonecomplete will f
* [tzdata-southamerica](https://npmjs.com/package/tzdata-southamerica)
* [tzdata-systemv](https://npmjs.com/package/tzdata-systemv)

Separating the TZ data from timezonecomplete has three advantages:

1. The data becomes useful to other modules than just timezonecomplete
1. By choosing for e.g. 'tzdata-northamerica', you can install just the time zones you need, which is especially handy for browser use (smaller footprint).
1. The upgrades to the TZ data become independent of changes to timezonecomplete. That means you do not have to upgrade to the latest timezonecomplete version to get the latest TZ data.

### Node.JS

Simply install timezonecomplete and it will also install all time zones.

### Browserify

You need to manually add the tzdata JSON files from the NPM modules above, e.g.:
If you use browserify, There are two options:
1. Require the .json files in your code and pass them to TzDatabase.init() before using any timezonecomplete functionality.
1. Include the tzdata .json files manually using browserify.require()

Option 1:
```
// browserify will pick these up. You may need to set the 'extensions' option of browserify to include .json files
// NOTE in TypeScript, also use 'const' NOT 'import'!
const northamerica = require('tzdata-northamerica');
const etcetera = require('tzdata-etcetera');
const tc = require('timezonecomplete');
// Do this before creating e.g. tc.DateTime objects.
// In this example we use only part of the timezone database to reduce bundle size.
// Note you could whittle down the zones and rules further if you like by e.g. excluding rules pre-1990.
// That's at your own risk though
tc.TzDatabase.init([northamerica, etcetera]);
```

Option 2:
```
// Manual browserifying ambient JSON data
var fs = require('fs');
var glob = require('glob');
var browserify = require('browserify');
Expand All @@ -44,7 +61,7 @@ browserify({
extensions: ['.js', '.json'], // needed to include the tzdata modules
debug: true
})
.require('./node_modules/tzdata/timezone-data.json', {expose: 'tzdata'}) // add tzdata
.require('./node_modules/tzdata/timezone-data.json', {expose: 'tzdata'}) // add 'tzdata' and make it available globally under its own name
.bundle()
.pipe(fs.createWriteStream('./dist/bundle.js'));
```
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timezonecomplete",
"version": "5.3.0",
"version": "5.4.0",
"description": "DateTime, TimeZone, Duration and Period library aimed at providing a consistent and complete date-time interface, away from the original JavaScript Date class.",
"keywords": [
"Date",
Expand Down Expand Up @@ -47,7 +47,9 @@
"karma": "npm run bundle_tests && npm run exec_karma",
"all": "npm run clean && npm run build && npm run test && npm run karma"
},
"dependencies": {},
"dependencies": {
"tzdata": "^1.0.0"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/lolex": "^1.5.30",
Expand Down

0 comments on commit be236ce

Please sign in to comment.