No description
Find a file
2021-06-30 19:03:54 -05:00
db tz-erl: Better document problem when a zone begins or ends using DST. 2015-11-21 22:48:36 +00:00
include Reworked so that the tz_index is built as a module, rather than a raw dict, so it passes dialyzer 2021-06-30 18:42:38 -05:00
src tz_index.hrl is gone 2021-06-30 18:48:59 -05:00
.gitignore Rename project to qdate_localtime 2016-07-06 17:27:10 -05:00
ibuild.escript Reworked so that the tz_index is built as a module, rather than a raw dict, so it passes dialyzer 2021-06-30 18:42:38 -05:00
LICENSE license changed to apache 2015-09-19 09:39:33 +03:00
Makefile Reworked so that the tz_index is built as a module, rather than a raw dict, so it passes dialyzer 2021-06-30 18:42:38 -05:00
README.md Rename project to qdate_localtime 2016-07-06 17:27:10 -05:00
rebar.config Reworked so that the tz_index is built as a module, rather than a raw dict, so it passes dialyzer 2021-06-30 18:42:38 -05:00
rebar.lock Rebar3 / hex compatiblility. 2016-01-31 08:25:37 -06:00
rebar3 Update rebar3 2021-06-30 19:03:54 -05:00

NOTE

This is a fork of erlang_localtime, modified specifically for compatibility with qdate. The two are mostly compatible, but have diverged a bit over the years. The qdate tests will not pass if the original erlang_localtime dependency is used due to some subtle differences to attempt to make qdate a little bit smarter.

Public exports

  • utc_to_local(DateTime, Timezone) - converts UTC time to local according to specified Timezone
  • local_to_utc(DateTime, Timezone) - converts local time to UTC
  • local_to_local(DateTime, TimezoneFrom, TimezoneTo) - converts local time to local
  • tz_name(DateTime, Timezone) - returns a timezone name (E.g. MSK, MSD, etc)
  • tz_shift(DateTime, Timezone) - returns time difference between local datetime and GMT
  • tz_shift(DateTime, TimezoneFrom, TimezoneTo) - returns time difference between local datetime and required timezone Where DateTime = {date(), time()} TimeZone(To, From) = String(). E.g. “Europe/Moscow”, “America/NewYork”. Or abbreviations "MSK", "MSD", etc. Note: abbreviation is just used to find appropriate timezone name. If you want to convert "MSK" -> "PDT", but source timezone is not in daylight saving, it will be corrected by library and "MSK" -> "PST" conversion will be made.

Examples of usage

Converts UTC time to local one

localtime:utc_to_local({{2010, 7, 22}, {17, 56, 23}, "Europe/Moscow").

{{2010,10,10},{21,56,23}}

Converts local time to UTC one

localtime:local_to_utc({{2010, 10, 10}, {21, 56, 23}}, "Europe/Moscow").

{{2010,10,10},{17,56,23}}

Converts time from one local timezone to another local one

localtime:local_to_local({{2010, 10, 10}, {21, 56, 23}}, "Europe/Moscow", "Australia/Sydney").

{{2010,10,11},{3,56,23}}

Returns timezone name

localtime:tz_name({{2010, 10, 10}, {21, 56, 23}}, "Europe/Moscow").

{"MSK","MSK"}

localtime:tz_name({{2010,10,11},{3,56,23}}, "Australia/Sydney").

{"EST","EST"}

Calculates time difference between UTC and local one

localtime:tz_shift({{2013, 01, 22}, {18, 17, 00}}, "Europe/Moscow").

{'+',4,0}

localtime:tz_shift({{2013, 01, 22}, {18, 17, 00}}, "America/New York").

{'-',5,0}

Calculates time difference between two local timezones

localtime:tz_shift({{2013, 01, 22}, {18, 17, 00}}, "America/New York", "Europe/Moscow").

{'+',9,0}