lots of work towards flattening the records. stalled at ezic_rule:next_event/4

This commit is contained in:
aj
2010-11-07 18:32:37 -08:00
parent c795abf2b6
commit 9ad8f3c826
12 changed files with 479 additions and 115 deletions

View File

@@ -1,11 +1,13 @@
-module(ezic_zone).
-include("include/ezic.hrl").
-include_lib("eunit/include/eunit.hrl").
-export([
current/1
, current_as_of_utc/2
, sort/2
, revsort/2
, split_by_name/2
, sort_ascending/2
, sort_descending/2
, offset_sec/1
]).
@@ -28,8 +30,8 @@ current_as_of_utc(UTCDatetime, TzName) ->
get_zone_utc(_, []) ->
erlang:error(no_current);
get_zone_utc(UTCDatetime, Zones) ->
SortedZones= lists:sort(fun revsort/2, Zones),
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.
@@ -43,17 +45,29 @@ get_zone_utc(UTCDatetime, Zones) ->
sort(#zone{until=U1}, #zone{until=U2}) ->
% returns {[SimilarZone], [DifferentZone]}
% where Similar Zones are those with the same name as Zone
% and DifferentZones are all the rest
split_by_name(#zone{name=N}, Zones) ->
lists:partition(
fun(#zone{name=NI}) ->
N =:= NI
end
, Zones).
sort_descending(#zone{until=U1}, #zone{until=U2}) ->
ezic_date:compare_datetimes(U2, U1).
revsort(Z1=#zone{}, Z2=#zone{}) ->
not sort(Z1, Z2).
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_datetimes(Until, UTCDatetime).
%% older_zone(#zone{until=Until}, UTCDatetime) ->
%% ezic_date:compare_datetimes(Until, UTCDatetime).