DateTime, TimeZone, Duration and Period library aimed at providing a consistent and complete date-time interface, away from the original JavaScript Date class.
npm install timezonecomplete
npm install timezonecomplete
`
Then require the timezonecomplete module in your code. Timezonecomplete will automatically find any installed tzdata modules:
`javascript
var tc = require("timezonecomplete");
`
$3
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');
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'));
`
$3
Use a >=2.x (beta) version of webpack, to avoid warnings. Then, use a plugin in your webpack configuration to load the time zone data you need.
`javascript
plugins: [
new webpack.ContextReplacementPlugin(
/[\/\\]node_modules[\/\\]timezonecomplete[\/\\]/,
path.resolve("tz-database-context"),
{
"tzdata-backward-utc": "tzdata-backward-utc",
"tzdata-etcetera": "tzdata-etcetera",
"tzdata-europe": "tzdata-europe"
}
)
]
`
To install a beta version of webpack, first, look up the latest unstable version using:
`
npm show webpack versions --json
`
Then, install the specific version by specifying it behind an @-sign (in this example 2.2.0-rc3) like this:
`
npm install --save-dev webpack@2.2.0-rc.3
`
$3
Timezonecomplete comes with a bundle and a minified bundle. Both are UMD (isomorphic) modules.
Next to these bundles, you also need one or more of the bundles from the tzdata modules listed above.
You can find examples of using timezonecomplete in a browser in the examples directory, both using Require.JS and ambient.
`html
Timezonecomplete Browser Example
The difference between local time and UTC is: