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:
29
src/ezic_zone.erl
Normal file
29
src/ezic_zone.erl
Normal 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).
|
||||
Reference in New Issue
Block a user