TzWorld.Backend behaviour (TzWorld v2.5.0)

Copy Markdown View Source

The behaviour a time zone lookup backend implements.

TzWorld answers lookups by calling the running backend, normally TzWorld.Backend.SpatialIndex. A custom backend implements these callbacks, runs in the application's supervision tree registered under its module name, and is made the default with:

config :tz_world, default_backend: MyApp.TzWorldBackend

TzWorld validates points before it calls a backend, so a backend always receives a Geo.Point whose coordinates are numbers within range.

Summary

Types

A point whose coordinates are {lng, lat}.

Latitude in degrees, from -90 to 90.

Longitude in degrees, from -180 to 180.

Callbacks

Returns every time zone at a point, as {:ok, time_zones} with an empty list if no time zone contains it.

Reloads the time zone data after mix tz_world.update has installed a new release.

Returns the time zone at a point: {:ok, time_zone}, or {:error, :time_zone_not_found} if no time zone contains it.

Returns the version of the loaded time zone data, as {:ok, version}.

Types

geo()

@type geo() :: Geo.Point.t()

A point whose coordinates are {lng, lat}.

lat()

@type lat() :: number()

Latitude in degrees, from -90 to 90.

lng()

@type lng() :: number()

Longitude in degrees, from -180 to 180.

Callbacks

all_timezones_at(geo)

@callback all_timezones_at(geo()) :: {:ok, [String.t()]} | {:error, atom()}

Returns every time zone at a point, as {:ok, time_zones} with an empty list if no time zone contains it.

reload_timezone_data()

@callback reload_timezone_data() :: {:ok, term()} | {:error, term()}

Reloads the time zone data after mix tz_world.update has installed a new release.

timezone_at(geo)

@callback timezone_at(geo()) :: {:ok, String.t()} | {:error, atom()}

Returns the time zone at a point: {:ok, time_zone}, or {:error, :time_zone_not_found} if no time zone contains it.

version()

@callback version() :: {:ok, String.t()} | {:error, term()}

Returns the version of the loaded time zone data, as {:ok, version}.