repaired ezic_date:add_offset. able to normalize plain dates. notes and tests

add_offset was calculating DST differences wrong. It assumed to lose an hour, DST would be {-1,0,0}, in fact, DST went from {1,0,0} to {0,0,0}. add_offset now uses their differences (hence requires both as arguments)
normalize/2 was added to be able to set an arbitrary flag on a plain (i.e. native erlang datetime tuple) date. This is complicated by the fact that atoms "minimum", "max", etc. are still valid and need to fall through the normalization unaltered (for now).
This commit is contained in:
aj
2010-11-12 03:07:15 -08:00
parent 3e77287db6
commit a7b0adcbce
4 changed files with 155 additions and 72 deletions

View File

@@ -94,14 +94,16 @@ project_end_utc(Zone=#zone{}, DSTOffset) ->
% 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.
%% BAD!!! UCTFrom is not used!
%% 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. see unit tests for examples.
next(ZoneList, UTCFrom, DSTOff) ->
?debugMsg("next:"),
?debugVal(ZoneList),
?debugVal(UTCFrom),
DatedList= lists:map(
fun(Z=#zone{until=Until, gmtoff=Offset})->
NUntil= ezic_date:normalize(Until),
@@ -109,6 +111,8 @@ next(ZoneList, UTCFrom, DSTOff) ->
{UTCDt, Z}
end
, ZoneList),
FilteredList= lists:filter(fun({IDt,_})-> UTCFrom =< IDt end, DatedList),
SortedList= lists:sort(FilteredList),
FilteredList= lists:filter(fun({IDt,_})-> ezic_date:compare(UTCFrom, IDt) end, DatedList),
%x ?debugVal(FilteredList),
SortedList= lists:sort(fun({X,_},{Y,_})->ezic_date:compare(X,Y)end, FilteredList),
[Z || {_,Z}<- SortedList].