Use the IANA Time Zone Database to build a set of JSON files for all time zones. Each JSON file contains a time zone's offset at 1970 and a list of offset changes through 2037.
Note: The standard file type for time zone data is TZif; you may consider serving TZif files instead of JSON files.
./build.sh
- clones the IANA Time Zone Database repository
- compiles zone information files for the latest release
- uses a script from tz.js to read the compiled files
- writes a set of JSON files to
dist/<version>
For example, if the latest release is version 2018e
, then the file for America/Los_Angeles will be written to dist/2018e/America/Los_Angeles.json
.
The elm/time
library provides a Posix
type for representing an instant in time. Extracting human-readable parts from a Posix
time requires a Time.Zone
. These JSON files can be used by Elm applications that need Time.Zone
values at runtime.
For an example of fetching and decoding Time.Zone
values, see the getZone
function in this file; it takes a path to your JSON files and returns a task for getting the local zone name and zone as a ( String, Time.Zone )
.
import Time
import TimeZone.Json exposing (Error)
getLocalZone : Task Error ( String, Time.Zone )
getLocalZone =
TimeZone.Json.getZone "/dist/2018e"
See examples/GetZone.elm
for a full example.