View Source TzWorld (TzWorld v1.4.1)

Resolve a timezone name from coordinates.

Summary

Functions

Returns all timezone name found for the given coordinates specified as either a Geo.Point, a Geo.PointZ or a tuple {lng, lat}

Returns the OTP app name of :tz_world

Reload the timezone geometry data.

Returns the first timezone name found for the given coordinates specified as either a Geo.Point, a Geo.PointZ or a tuple {lng, lat}

Returns the installed version of time zone data

Types

@type backend() :: module()

Functions

Link to this function

all_timezones_at(point, backend \\ fetch_backend())

View Source
@spec all_timezones_at(Geo.Point.t(), backend()) :: {:ok, [String.t()]}
@spec all_timezones_at(Geo.PointZ.t(), backend()) :: {:ok, [String.t()]}
@spec all_timezones_at(
  {lng :: number(), lat :: number()},
  backend()
) :: {:ok, [String.t()]}

Returns all timezone name found for the given coordinates specified as either a Geo.Point, a Geo.PointZ or a tuple {lng, lat}

Arguments

  • point is a Geo.Point.t() a Geo.PointZ.t() or a tuple {lng, lat}

  • backend is any backend access module.

Returns

  • {:ok, timezone} or

  • {:error, :time_zone_not_found}

Notes

Note that the point is always expressed as lng followed by lat.

Examples

iex> TzWorld.all_timezones_at(%Geo.Point{coordinates: {3.2, 45.32}})
{:ok, ["Europe/Paris"]}

iex> TzWorld.all_timezones_at({3.2, 45.32})
{:ok, ["Europe/Paris"]}

iex> TzWorld.all_timezones_at({0.0, 0.0})
{:ok, []}

The algorithm starts by filtering out timezones whose bounding box does not contain the given point.

Once filtered, all timezones which contains the given point is returned, or an error tuple if none of the timezones match.

In rare cases, typically due to territorial disputes, one or more timezones may apply to a given location. This function returns all time zones that match.

Returns the OTP app name of :tz_world

Reload the timezone geometry data.

This allows for the data to be reloaded, typically with a new release, without restarting the application.

Link to this function

timezone_at(point, backend \\ fetch_backend())

View Source
@spec timezone_at(Geo.Point.t(), backend()) :: {:ok, String.t()} | {:error, atom()}
@spec timezone_at(Geo.PointZ.t(), backend()) :: {:ok, String.t()} | {:error, atom()}
@spec timezone_at(
  {lng :: number(), lat :: number()},
  backend()
) :: {:ok, String.t()} | {:error, atom()}

Returns the first timezone name found for the given coordinates specified as either a Geo.Point, a Geo.PointZ or a tuple {lng, lat}

Arguments

  • point is a Geo.Point.t() a Geo.PointZ.t() or a tuple {lng, lat}

  • backend is any backend access module.

Returns

  • {:ok, timezone} or

  • {:error, :time_zone_not_found}

Notes

Note that the point is always expressed as lng followed by lat.

Examples

iex> TzWorld.timezone_at(%Geo.Point{coordinates: {3.2, 45.32}})
{:ok, "Europe/Paris"}

iex> TzWorld.timezone_at({3.2, 45.32})
{:ok, "Europe/Paris"}

iex> TzWorld.timezone_at({0.0, 0.0})
{:error, :time_zone_not_found}

The algorithm starts by filtering out timezones whose bounding box does not contain the given point.

Once filtered, the first timezone which contains the given point is returned, or an error tuple if none of the timezones match.

In rare cases, typically due to territorial disputes, one or more timezones may apply to a given location. This function returns the first time zone that matches.

@spec version() :: {:ok, String.t()} | {:error, :enoent}

Returns the installed version of time zone data

Example

TzWorld.version
=> {:ok, "2020d"}