timezonedb-node

An asynchronous client library for TimeZoneDB API.

Usage no npm install needed!

<script type="module">
  import timezonedbNode from 'https://cdn.skypack.dev/timezonedb-node';
</script>

README

timezonedb-node Logo

An asynchronous client library for TimeZoneDB API.

NPM Package Version NPM Package License NPM Package Downloads devDependencies Status

Node Version Travis CI Build Status Code Climate Status Code Climate Test Coverage Status Inch CI Documentation Coverage Status

NPM Package Statistics

Installation

npm install timezonedb-node

Quick Start

The quickest way to get started is by executing following code:

var timezonedb = require('timezonedb-node')('YOUR_API_KEY');

timezonedb.getTimeZoneData({
    zone: 'Australia/Melbourne'
}, function (error, data) {
    if (!error) {
        console.log(data);
    } else {
        console.error(error);
    }
});

If everything went well, you'll see something like this in your console:

{ 
    status: 'OK',
    message: '',
    countryCode: 'AU',
    zoneName: 'Australia/Melbourne',
    abbreviation: 'AEST',
    gmtOffset: '36000',
    dst: '0',
    timestamp: 1438547603
}

Documentation

getTimeZoneDB

Requests timezone data.

Options

  • zone(default: none, required: true) - Zone name of an area.
  • lat(default: none, required: true if zone not specified) - Latitude of a city.
  • lng(default: none, required: true if zone not specified) - Longitude of a city.
  • time(default: Current Unix timestamp, required: false) - Unix time.

Examples

Requests timezone data of zone.

timezonedb.getTimeZoneData({
    zone: 'Australia/Melbourne'
}, function (error, data) {
    if (!error) {
        console.log(data);
    } else {
        console.error(error);
    }
});

Requests timezone data of location.

timezonedb.getTimeZoneData({
    lat: 53.7833,
    lng: -1.75
}, function (error, data) {
    if (!error) {
        console.log(data);
    } else {
        console.error(error);
    }
});

Requests timezone data of location with manually set time.

timezonedb.getTimeZoneData({
    lat: 53.7833,
    lng: -1.75,
    time: 1366552200
}, function (error, data) {
    if (!error) {
        console.log(data);
    } else {
        console.error(error);
    }
});

Errors

When errors occur, you receive an error object with default properties as a first argument of the callback.

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

License

Distributed under the MIT License.