The TZ data is now installed as a separate NPM module 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().
- tzdata-africa
- tzdata-antarctica
- tzdata-asia
- tzdata-australasia
- tzdata-backward: contains deprecated zone names, depends on the other modules
- tzdata-backward-utc: contains only the UTC and GMT zones of backward, depends on tzdata-etcetera
- tzdata-etcetera
- tzdata-europe
- tzdata-northamerica
- tzdata-pacificnew
- tzdata-southamerica
- tzdata-systemv
Separating the TZ data from timezonecomplete has three advantages:
- The data becomes useful to other modules than just timezonecomplete
- 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).
- 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.
Simply install timezonecomplete and it will also install all time zones.
If you use browserify, There are two options:
- Require the .json files in your code and pass them to TzDatabase.init() before using any timezonecomplete functionality.
- 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');
browserify({
entries: glob.sync('./src/*.js'),
extensions: ['.js', '.json'], // needed to include the tzdata modules
debug: true
})
.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'));
You need to ensure that one or more bundle files from the NPM modules above are loaded, e.g. like this:
require.config({
baseUrl: '.',
paths: {
"timezonecomplete": 'timezonecomplete',
"tzdata-backward-utc": 'tzdata-backward-utc',
"tzdata-etcetera": 'tzdata-etcetera'
}
});
require(['timezonecomplete', 'tzdata-backward-utc', 'tzdata-etcetera'], function(tc) {
});
The tzdata-* NPM modules contain a bundled .js file that you need to include in the HTML before including timezonecomplete. Thus, your script tags should look like this:
<script src="./tzdata.js"></script>
<script src="./timezonecomplete.js"></script>
Only minor breaking changes - these classes should not be used much at all.
- unixToTimeNoLeapSecs() returns a TimeComponents instead of a TimeStruct now. Use new TimeStruct(unixMillis) instead.
- timeToUnixNoLeapSecs() now has all of its parameters non-optional. Use TimeStruct.unixMillis instead.
- TimeStruct has changed (you should not have to use this):
- The constructor no longer takes loose year, month, day, ... arguments. Use either TimeStruct({ year, month, day}) constructor or TimeStruct.fromComponents()
- Instead of TimeStruct#toUnixNoLeapSecs(), use the TimeStruct#unixMillis property
- the lessThan() method is gone, simply use the less-than operator < to compare TimeStructs
- The UtcMillisCache is gone.
The Period class has changed.
- The Period#findLast() method now also returns timestamps before the period start date, instead of stopping there. Change your application logic if it depends on periods not returning timestamps before the start date.
- Change your application logic if it depends on Period#equals() to mean 'same start date and same interval'. Consider using Period#identical() for that purpose if it isn't too strict for you.
- Rename all calls to Period#start() to Period#reference(). The start() method is deprecated.
Javascript users don't need to do anything. Typescript users should:
- Remove any triple-slash references to the timezonecomplete typings file
- Ensure tsc is called with 'node' module resolution (which is the default)