TimeZoneDB
A simple promise-based (async/await) client library for interacting with TimeZoneDB API with Typescript type definitions.
Install
npm install --save timezonedb
Simple Example
const Tzdb = Tzdb; const tzdb = apiToken: '123abc'; const go = async { const tz = await tzdb; console;};
Documentation
Known Limitations
The premium methods (getTimeZoneByCity()
and getTimeZoneByIP()
) are untested since I don't have a premium account. Pull requests are gladly accepted if you test and the code needs changed.
Class vs request methods
You can either use new Tzdb(TZDBConfig)
and use the instance methods or you can import the request functions (e.g. listTimeZones(TZDBConfig, ListTimeZonesRequest)
directly). The class is just a wrapper for calling the request functions with the provided config.
For example:
; ; tzdb.getTimeZoneByZone .thenconsole.log .catchconsole.error;
is equivalent to:
; ; getTimeZoneByZoneconfig, .thenconsole.log .catchconsole.error;
Tzdb Class Methods
```ts
class Tzdb {
listTimeZones(ListTimeZonesRequest) // returns `Promise<TimeZone[]>`
getTimeZoneByZone(GetTimeZoneRequestByZone) // returns `Promise<TimeZoneDetail>`
getTimeZoneByPosition(GetTimeZoneRequestByPosition) // returns `Promise<TimeZoneDetail>`
getTimeZoneByCity(GetTimeZoneRequestByCity) // returns `Promise<TimeZoneDetail[]>`
getTimeZoneByIP(GetTimeZoneRequestByIP) // returns `Promise<TimeZoneDetail>`
convertTimeZone(ConvertTimeZoneRequest) // returns `Promise<TimeZoneConversion>`
}
```
Request functions
```ts
import * as tzdb from 'timezonedb';
tzdb.listTimeZones(TZDBConfig, ListTimeZonesRequest) // returns `Promise<TimeZone[]>`
tzdb.getTimeZoneByZone(TZDBConfig, GetTimeZoneRequestByZone) // returns `Promise<TimeZoneDetail>`
tzdb.getTimeZoneByPosition(TZDBConfig, GetTimeZoneRequestByPosition) // returns `Promise<TimeZoneDetail>`
tzdb.getTimeZoneByCity(TZDBConfig, GetTimeZoneRequestByCity) // returns `Promise<TimeZoneDetail[]>`
tzdb.getTimeZoneByIP(TZDBConfig, GetTimeZoneRequestByIP) // returns `Promise<TimeZoneDetail>`
tzdb.convertTimeZone(TZDBConfig, ConvertTimeZoneRequest) // returns `Promise<TimeZoneConversion>`
```
Parameters
-
TZDBConfig
These values can all be set by corresponding environment variables or passed as a config object to the class constructor or the request functions.
-
ListTimeZonesRequest
-
GetTimeZoneRequestByZone
-
GetTimeZoneRequestByPosition
-
GetTimeZoneRequestByCity
(premium and untested) -
GetTimeZoneRequestByIP
(premium and untested) -
ConvertTimeZoneRequest
Responses
-
TimeZone
-
TimeZoneDetail
-
TimeZoneConversion
Examples
List Time Zones
; listTimeZones, .thenconsole.log .catchconsole.error;
Get Time Zones by Position
; getTimeZoneByPosition, .thenconsole.log .catchconsole.error;
More examples can be found in the /examples
folder.