flattening algorithm needs to be reworked.
also, datetime methods aren't consistent in their naming and return values.
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
, current/1
|
||||
, current_as_of_utc/2
|
||||
, split_by_name/2
|
||||
, sort_ascending/2
|
||||
, sort_descending/2
|
||||
, offset_sec/1
|
||||
|
||||
, project_end/2
|
||||
, project_end_utc/2
|
||||
, next/3
|
||||
]).
|
||||
|
||||
|
||||
@@ -50,16 +50,6 @@ current_as_of_utc(UTCDatetime, TzName) ->
|
||||
get_zone_utc(_, []) ->
|
||||
erlang:error(no_current);
|
||||
get_zone_utc(_UTCDatetime, Zones) ->
|
||||
_SortedZones= lists:sort(fun sort_descending/2, Zones),
|
||||
%% [CZone|_]= lists:dropwhile(fun(SZ)-> older_zone_utc(SZ, UTCDatetime) end, SortedZones),
|
||||
%% CZone.
|
||||
|
||||
|
||||
%% begin with GMT offset.
|
||||
%% foreach rule (oldest first)
|
||||
%% see whether until=(standard|wall|utc) time
|
||||
%%
|
||||
|
||||
not_done.
|
||||
|
||||
|
||||
@@ -76,14 +66,6 @@ split_by_name(#zone{name=N}, Zones) ->
|
||||
, Zones).
|
||||
|
||||
|
||||
sort_descending(#zone{until=U1}, #zone{until=U2}) ->
|
||||
ezic_date:compare(U2, U1).
|
||||
|
||||
sort_ascending(Z1=#zone{}, Z2=#zone{}) ->
|
||||
not sort_descending(Z1, Z2).
|
||||
|
||||
|
||||
|
||||
% @bug doesn't normalize times. Times are self-relative (to standard time), and Now may come from any timezone unless we're careful about that.
|
||||
%% older_zone(#zone{until=Until}, UTCDatetime) ->
|
||||
%% ezic_date:compare(Until, UTCDatetime).
|
||||
@@ -98,9 +80,28 @@ offset_sec(Zone) ->
|
||||
|
||||
% returns the UTC datetime projected for zone end (given current DST Offset)
|
||||
project_end(#zone{until=Until, gmtoff=Offset}, DSTOffset) ->
|
||||
{_,_,UTCDatetime}= ezic_date:all_times(Until, Offset, DSTOffset),
|
||||
ezic_date:all_times(Until, Offset, DSTOffset).
|
||||
|
||||
% returns just the UTC datetime projected for zone end
|
||||
project_end_utc(Zone=#zone{}, DSTOffset) ->
|
||||
{_,_,UTCDatetime}= project_end(Zone, DSTOffset),
|
||||
UTCDatetime.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
% returns {Zone, Rest} where Zone is the next zone after UTCFrom,
|
||||
% subject to the DST offset.
|
||||
% Note that dst differences *can* change which zone comes next,
|
||||
% though it's very unlikely (and does not exist in the current tz database files).
|
||||
% this method covers that event, anyhow.
|
||||
next(ZoneList, UTCFrom, DSTOff) ->
|
||||
DatedList= lists:map(
|
||||
fun(Z=#zone{until=Until, gmtoff=Offset})->
|
||||
NU= ezic_date:normalize(Until),
|
||||
{_,_,UTCDt}= ezic_date:all_times(NU, Offset, DSTOff),
|
||||
{UTCDt, Z}
|
||||
end
|
||||
, ZoneList),
|
||||
[{_,Zone} | DRest]= lists:sort(DatedList),
|
||||
{Zone, [R || {_,R}<- DRest]}.
|
||||
|
||||
Reference in New Issue
Block a user