qdate_localtime/README.md

64 lines
2.4 KiB
Markdown
Raw Permalink Normal View History

2016-07-06 17:27:10 -05:00
## NOTE
This is a fork of the excellent library,
[erlang_localtime](https://github.com/dmitryme/erlang_localtime). The purpose
of this fork is specifically for compatibility with
2016-07-06 17:27:10 -05:00
[qdate](https://github.com/choptastic/qdate). The two are mostly compatible,
but have diverged slightly 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.
2016-07-06 17:27:10 -05:00
2012-11-02 14:53:09 +04:00
#### Public exports
2010-10-05 06:36:03 -07:00
* `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
2010-10-05 06:36:03 -07:00
Where
DateTime = {date(), time()}
2010-12-18 10:28:56 -08:00
TimeZone(To, From) = String(). E.g. “Europe/Moscow”, “America/NewYork”. Or abbreviations "MSK", "MSD", etc. Note:
2010-12-18 21:11:42 +03:00
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.
2013-01-23 18:55:23 +04:00
#### Examples of usage
2013-01-23 19:00:32 +04:00
Converts UTC time to local one
2013-01-23 18:55:23 +04:00
>localtime:utc_to_local({{2010, 7, 22}, {17, 56, 23}, "Europe/Moscow").
2014-03-07 10:08:12 +04:00
>
2013-01-23 18:55:23 +04:00
>{{2010,10,10},{21,56,23}}
2013-01-23 19:00:32 +04:00
Converts local time to UTC one
2013-01-23 18:55:23 +04:00
>localtime:local_to_utc({{2010, 10, 10}, {21, 56, 23}}, "Europe/Moscow").
2014-03-07 10:08:12 +04:00
>
2013-01-23 18:55:23 +04:00
>{{2010,10,10},{17,56,23}}
2013-01-23 19:00:32 +04:00
Converts time from one local timezone to another local one
2013-01-23 18:55:23 +04:00
>localtime:local_to_local({{2010, 10, 10}, {21, 56, 23}}, "Europe/Moscow", "Australia/Sydney").
2014-03-07 10:08:12 +04:00
>
>{{2010,10,11},{3,56,23}}
2013-01-23 18:55:23 +04:00
2013-01-23 19:00:32 +04:00
Returns timezone name
2013-01-23 18:55:23 +04:00
>localtime:tz_name({{2010, 10, 10}, {21, 56, 23}}, "Europe/Moscow").
2014-03-07 10:08:12 +04:00
>
2013-01-23 18:55:23 +04:00
>{"MSK","MSK"}
>localtime:tz_name({{2010,10,11},{3,56,23}}, "Australia/Sydney").
2014-03-07 10:08:12 +04:00
>
2013-01-23 18:55:23 +04:00
>{"EST","EST"}
2013-01-23 19:00:32 +04:00
Calculates time difference between UTC and local one
>localtime:tz_shift({{2013, 01, 22}, {18, 17, 00}}, "Europe/Moscow").
2014-03-07 10:08:12 +04:00
>
2013-01-23 19:00:32 +04:00
>{'+',4,0}
>localtime:tz_shift({{2013, 01, 22}, {18, 17, 00}}, "America/New York").
2014-03-07 10:08:12 +04:00
>
2013-01-23 19:00:32 +04:00
>{'-',5,0}
Calculates time difference between two local timezones
>localtime:tz_shift({{2013, 01, 22}, {18, 17, 00}}, "America/New York", "Europe/Moscow").
2014-03-07 10:08:12 +04:00
>
2013-01-23 19:00:32 +04:00
>{'+',9,0}