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:
aj
2010-11-04 04:20:38 -07:00
parent d48d32ddbb
commit 7dd76519a0
10 changed files with 236 additions and 23 deletions

29
src/ezic_zone.erl Normal file
View File

@@ -0,0 +1,29 @@
-module(ezic_zone).
-include("include/ezic.hrl").
-export([current/2, sort/2, revsort/2, offset_sec/1]).
current(_, []) ->
erlang:error(no_current);
current(Now, Zones) ->
SortedZones= lists:sort(fun revsort/2, Zones),
% ?debug("SortedZones: ~p", [SortedZones]),
[CZone|_]= lists:dropwhile(fun(SZ)-> older_zone(SZ, Now) end, SortedZones),
CZone.
sort(#zone{until=U1}, #zone{until=U2}) ->
ezic_date:compare_datetimes(U2, U1).
revsort(Z1=#zone{}, Z2=#zone{}) ->
not sort(Z1, Z2).
older_zone(Zone=#zone{until=Until}, Now) ->
ezic_date:compare_datetimes(Until, Now).
offset_sec(Zone) ->
calendar:time_to_seconds((Zone#zone.gmtoff)#tztime.time).