Quickly get timezone names and metadata from the IANA into your application in the format you want.
Written in Typescript so you can import the shape of the data and get awesome type completion.
100% test coverage using Jasmine and WallabyJS
A large part of this codebase is using or was inspired by packages created by shinnn. Using handlebars templates to quickly create custom JSON shapes inspired by this project Graphql Code Generator
npm install iana-tz-json-generator-and-importer
See ./timezones for currently available timezones Timezones are named after the IANA version and file used in generation
{version}-{IANAFileName}-{handlebarsTemplateName}.json
import {loadIANATzJsonFile} from 'iana-tz-json-generator-and-importer';
import {IAllFields} from 'iana-tz-json-generator-and-importer/timezones/all-fields';
async function loadAllFields() {
const allFields = await loadIANATzJsonFile('2018c-zone1970-all-fields.json');
const values: IAllFields = JSON.parse(allFields);
}
Generate timezone JSON files using Handlebar templates.
This allows you to quickly and easily format the data exactly how you want it to.
clone the package
npm install
- Add your own custom handlebars template to the
./template
folder - Add typescript typings in the
./template
folder - npm run generate-json-files-and-typescript-types
- submit pull request
./templates/all-fields.hbs
./templates/all-fields.ts typings for the JSON shape.
export interface IAllFields {
IANAVersion: string
numberOfZones: number
zones: IZones[]
}
export interface IZones {
countryCode: string
timezone: string
coordinates: {
latitude: ICoordinate,
longitude: ICoordinate
}
}
export interface ICoordinate {
sign: string
degree: number
minute: number
second?: number
}
{
"IANAVersion": "2018c",
"numberOfZones": 424,
"zones": [
{
"countryCode": "AD",
"timezone": "Europe/Andorra",
"coordinates": {
"latitude": {
"sign": "+",
"degree": 42,
"minute": 30
},
"longitude": {
"sign": "+",
"degree": 1,
"minute": 31
}
}
},
...
]
}
npm install iana-tz-json-generator-and-importer
- call:
createJSONFromTemplatesAndZoneData({ templatesPath: string, saveDirectory: string, zoneFileNames: string[] })
Load a string version of any IANA timezone data file from the IANA website with get-iana-tz-data
. Defaults include zone.tab and zone1970.tab.
Extract the latest IANA timezone data from the IANA website using extract-timezone-data
return as a JS object with Typescript typings.
- Make changes
- Commit those changes
npm run commit
- Test
npm run test
- Bump version in
package.json
- Generate changelog
npm run generate-changelog
- Commit
package.json
andCHANGELOG.md
files - Run npm
publish
- Git tag - needed by changelog to know what version to attribute the commits to
- Push