Class: TimeZones

PD. TimeZones


new TimeZones()

Provides utilities for looking up timezones for locations.

This class uses a detailed lookup table of latitude/longitude values to find the timezone for any location on the Earth's surface. Timezone boundaries are not straightforward and there is no obvious algorithm for accurately determining the timezone for every part of every country. This lookup table is accurate to within 0.5deg in both latitude and longitude, which should be sufficient for most design applications.

Longitude values must be given as Eastings ain degrees. This means that longitudes to the west of the Prime Meridian are negative (America) and those to the east are positive (Europe and Asia).

Latitude values must be given as Northings in degrees. This means that latitudes south of the Equator are negative (Australia and South America) and those to the north are positive (Canada, Europe and Russia).

Author:
  • drajmarsh
Example
const lng = -74.0060;
const lat = 40.7128;
const timezone = PD.TimeZones.lookup(lat, lng);

Methods


getIANA() <static>

Retrieve a list of world time zones.

Each entry in the list as a name and offset property (in decimal hours), with some also having a dst property giving daylight savings time periods.

This data is maintained by the Internet Assigned Numbers Authority (IANA) for use as a digital standard.

Returns:

Returns an array of IANA timezone data.

Type
Array

getStandardTimeZones() <static>

Retrieves an array of standard time zone offsets.

Each item in the list is an object with a name and value property, where the name is for display and the value is in decimal hours.

Returns:

Returns an array of standard time zone objects.

Type
Array

lookup(lat, lng) <static>

Searches for the timezone associated with the given location.

Parameters:
Name Type Description
lat number

The location latitude in decimal degrees (-90 to 90).

lng number

The location longitude in decimal degrees (-180 to 180).

Returns:

Returns a timezone offset in decimal hours.

Type
number

toStandardTimeZone(tz) <static>

Converts the given timezone to a standard time zone.

A standard timezone refers to the nearest region of the world with the given UTC time offset.

Parameters:
Name Type Description
tz number

The selected timezone in decimal time.

Returns:

Returns the closest standard timezone.

Type
number