happy path tested! current times correctly reported for LA, NY, Tokyo, and Jamaica!
Japan doesn't observer DST. I didn't know that.
This commit is contained in:
48
src/ezic.erl
48
src/ezic.erl
@@ -1,11 +1,37 @@
|
||||
-module(ezic).
|
||||
-include("include/ezic.hrl").
|
||||
|
||||
-export([load/1, time2time/3]).
|
||||
-export([dev_start/0]).
|
||||
-export([localtime/1, time2time/3]).
|
||||
-export([load/1, dev_start/0, test/0]).
|
||||
|
||||
|
||||
load(Folder) ->
|
||||
ezic_loader:load(Folder).
|
||||
-define(gs2dt(X), calendar:gregorian_seconds_to_datetime(X)).
|
||||
-define(dt2gs(X), calendar:datetime_to_gregorian_seconds(X)).
|
||||
|
||||
|
||||
|
||||
localtime(TzName) ->
|
||||
Now= erlang:universaltime(),
|
||||
|
||||
Zones= ezic_db:zones(TzName),
|
||||
% ?debug("All Zones: ~p", [Zones]),
|
||||
CZone= ezic_zone:current(Now, Zones),
|
||||
% ?debug("Current Zone: ~p", [CZone]),
|
||||
|
||||
RuleName= CZone#zone.rule,
|
||||
Rules= ezic_db:rules(RuleName),
|
||||
% ?debug("All Rules: ~p", [Rules]),
|
||||
CRule= ezic_rule:current(Now, Rules),
|
||||
% ?debug("Current Rule: ~p", [CRule]),
|
||||
|
||||
|
||||
OffsetSec= ezic_zone:offset_sec(CZone),
|
||||
DSTSec= ezic_rule:dst_sec(CRule),
|
||||
%
|
||||
|
||||
SecDiff= OffsetSec + DSTSec,
|
||||
?gs2dt(?dt2gs(Now) + SecDiff).
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,5 +41,19 @@ time2time(_DateTime, _FromTimeZone, _ToTimeZone) ->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
load(Folder) ->
|
||||
ezic_loader:load(Folder).
|
||||
|
||||
|
||||
dev_start() ->
|
||||
ezic:load(filename:join("priv","tzdata")).
|
||||
|
||||
|
||||
test() ->
|
||||
lists:foreach(
|
||||
fun(TZ)->
|
||||
io:format("~s: ~p~n", [TZ, localtime(TZ)])
|
||||
end,
|
||||
["Asia/Tokyo", "America/New_York", "America/Los_Angeles", "America/Jamaica"]).
|
||||
|
||||
Reference in New Issue
Block a user