diff --git a/README.md b/README.md index 0fef82f..dbb8a3e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 57a2ca7..f96117a 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -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) diff --git a/doc/UPGRADING.md b/doc/UPGRADING.md index b090635..73263d3 100644 --- a/doc/UPGRADING.md +++ b/doc/UPGRADING.md @@ -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) @@ -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'); @@ -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')); ``` diff --git a/package.json b/package.json index 68ffbab..e47fcab 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",