Coder Social home page Coder Social logo

tzdata's Introduction

Tzdata

Build Status Hex.pm version Hex.pm downloads

Tzdata. The timezone database in Elixir.

Extracted from the Calendar library.

As of version 1.1.1 the tz release 2021e is included in the package.

When a new release is out, it will be automatically downloaded at runtime.

The tz release version in use can be verified with the following function:

iex> Tzdata.tzdata_version
"2021e"

Getting started

To use the Tzdata library with Elixir 1.8+, add it to the dependencies in your mix file:

defp deps do
  [  {:tzdata, "~> 1.1"},  ]
end

In your application you can choose to globally configure Elixir to use Tzdata. This can be done by putting the following line in the config file of your application:

config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

That's it!

That allows you to use the Elixir standard library to use Tzdata to do time zone calculations. One example is getting the current time in a certain time zone:

iex> DateTime.now("Europe/Copenhagen")
{:ok, #DateTime<2018-11-30 20:51:59.076524+01:00 CET Europe/Copenhagen>}

If you do not want Elixir to have a time zone database globally defined you can instead pass the module name Tzdata.TimeZoneDatabase directly to the functions that need a time zone database:

DateTime.now("Europe/Copenhagen", Tzdata.TimeZoneDatabase)

Data directory and releases

The library uses a file directory to store data. By default this directory is priv. In some cases you might want to use a different directory. For instance when using releases this is recommended. If so, create the directory and make sure Elixir can read and write to it. Then use elixir config files like this to tell Tzdata to use that directory:

config :tzdata, :data_dir, "/etc/elixir_tzdata_data"

Add the release_ets directory from priv to that directory containing the 20xxx.ets file that ships with this library.

For instance with this config: config :tzdata, :data_dir, "/etc/elixir_tzdata_data" an .ets file such as /etc/elixir_tzdata_data/release_ets/2017b.ets should be present.

Automatic data updates

By default Tzdata will poll for timezone database updates every day. In case new data is available, Tzdata will download it and use it.

This feature can be disabled with the following configuration:

config :tzdata, :autoupdate, :disabled

Min and Max Year configuration

By default Tzdata will use 1900 for the min year to look at rules and 44 years + the current year for the max. This may be too much data for some (e.g. when using an embedded system), so we can configure the max and min years of data to use as well. This can greatly greatly reduce the size of the ets table created by :tzdata.

config :tzdata, :max_year, 2030
config :tzdata, :min_year, 2020

If the autoupdate setting is set to disabled, one has to manually put updated .ets files in the release_ets sub-dir of the "data_dir" (see the "Data directory and releases" section above). When IANA releases new versions of the time zone data, this Tzdata library can be used to generate a new .ets file containing the new data.

Changes from 0.1.x to 0.5.x

The 0.5.1+ versions uses ETS tables and automatically polls the IANA servers for updated data. When a new version of the timezone database is available, it is automatically downloaded and used.

For use with Calendar you can still specify tzdata ~> 0.1.7 in your mix.exs file in case you experience problems using version ~> 0.5.20

Hackney dependency and security

Tzdata depends on Hackney in order to do HTTPS requests to get new updates. This is done because Erlang's built in HTTP client httpc does not verify SSL certificates when doing HTTPS requests. Hackney verifies the certificate of IANA when getting new tzdata releases from IANA.

Documentation

Documentation can be found at http://hexdocs.pm/tzdata/

When new timezone data is released

IANA releases new versions of the timezone database frequently.

For users of Tzdata version 0.5.x+ the new database will automatically be downloaded, parsed, saved and used in place of the old data.

License

The tzdata Elixir library is released under the MIT license. See the LICENSE file.

The tz database files (found in the source_data directory of early versions) is public domain.

tzdata's People

Contributors

lau avatar paulswartz avatar jarrodmoldrich avatar wojtekmach avatar lowks avatar madsheep avatar alanj853 avatar adamu avatar lostkobrakai avatar edennis avatar fabienhenon avatar tsubery avatar hoyon avatar isaacsanders avatar weisslj avatar jbodah avatar msch avatar mathieuprog avatar mdoza avatar thefirstavenger avatar milmazz avatar sasa1977 avatar wingyplus avatar tbk145 avatar vitortrin avatar enerick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.