Removes extra whitespace at EOL

This commit is contained in:
Jorge Diz Pico
2013-02-28 11:27:28 +01:00
parent d7d8f70463
commit f216d3ddf8
18 changed files with 107 additions and 108 deletions

View File

@@ -1,7 +1,7 @@
ezic
====
ezic is a native erlang library for working with timezones. It parses the Olson timezone database files, allowing native erlang timezone lookup and zone conversions without the use of shell commands or a UNIX system.
ezic is a native erlang library for working with timezones. It parses the Olson timezone database files, allowing native erlang timezone lookup and zone conversions without the use of shell commands or a UNIX system.
See the [tz database](http://www.twinsun.com/tz/tz-link.htm) page for more information about the Olson database.
@@ -33,7 +33,7 @@ API
Example Setup
-----
# setup your local environment
mkdir -p priv/tzdata
@@ -44,7 +44,7 @@ Example Setup
# remove a few troublesome files
cd priv/tzdata
rm *.sh *.gz *.tab factory Makefile
# build and run ezic
cd -
make all run
@@ -63,7 +63,7 @@ This project is in the [public domain](http://en.wikipedia.org/wiki/Public_Domai
Contributed Code
----------------
To maintain ezic's status as a public domain work, all contributions must also be dedicated to the public domain.
To maintain ezic's status as a public domain work, all contributions must also be dedicated to the public domain.

View File

@@ -31,7 +31,7 @@ make_app([AppDirAtom]) ->
%% folder (assuming OTP directory structure)
get_modules(AppDir) ->
lists:map(
fun(X)-> filename:basename(X, ".erl") end,
fun(X)-> filename:basename(X, ".erl") end,
filelib:wildcard(
filename:join([AppDir, "src", "*.erl"])
)

View File

@@ -3,7 +3,7 @@
{registered, []},
{vsn, "0.2.0"},
{applications, [
kernel,
kernel,
stdlib
]},
{mod, {ezic_app, ezic_db_ets}},

View File

@@ -21,14 +21,14 @@ localtime(TzName) ->
utc_to_local(UTCDatetime, TzName) ->
NormalDatetime= ezic_date:normalize(UTCDatetime, u),
utc_to_local_handleFlatzone(UTCDatetime, ezic_db:flatzone(NormalDatetime, TzName)).
%% returns utc time for corresponding time in given timezone utc
local_to_utc(LocalDatetime, TzName) ->
NormalDatetime= ezic_date:normalize(LocalDatetime, w),
local_to_utc_handleFlatzone(LocalDatetime, ezic_db:flatzone(NormalDatetime, TzName)).

View File

@@ -1,7 +1,7 @@
%%%-------------------------------------------------------------------
%%% File : ezic_app.erl
%%% Author : aj <aj@fattie>
%%% Description :
%%% Description :
%%%
%%% Created : 15 Nov 2010 by aj <aj@fattie>
%%%-------------------------------------------------------------------
@@ -19,7 +19,7 @@
%% Function: start(Type, StartArgs) -> {ok, Pid} |
%% {ok, Pid, State} |
%% {error, Reason}
%% Description: This function is called whenever an application
%% Description: This function is called whenever an application
%% is started using application:start/1,2, and should start the processes
%% of the application. If the application is structured according to the
%% OTP design principles as a supervision tree, this means starting the
@@ -27,7 +27,7 @@
%%--------------------------------------------------------------------
start(_Type, StartArgs) ->
case ezic_sup:start_link(StartArgs) of
{ok, Pid} ->
{ok, Pid} ->
{ok, Pid};
Error ->
Error
@@ -37,7 +37,7 @@ start(_Type, StartArgs) ->
%% Function: stop(State) -> void()
%% Description: This function is called whenever an application
%% has stopped. It is intended to be the opposite of Module:start/2 and
%% should do any necessary cleaning up. The return value is ignored.
%% should do any necessary cleaning up. The return value is ignored.
%%--------------------------------------------------------------------
stop(_State) ->
ok.

View File

@@ -59,9 +59,9 @@ normalize({{Y,M,D}, T={_,_,_}}) ->
%% normalizes a date, and sets the #tztime{flag=Flag} if appropriate
%% @todo ensure flag is valid
%% @todo cover all the cases. this is currently just used for standard erlang datetimes
normalize({D={_,_,_},T={HH,_,_}}, Flag)
normalize({D={_,_,_},T={HH,_,_}}, Flag)
when is_atom(Flag), is_integer(HH) ->
DTz= {D, #tztime{time=T, flag=Flag}},
normalize(DTz);
@@ -73,7 +73,7 @@ normalize(D, Flag) ->
_ ->
erlang:error(badDateTime, D)
end.
@@ -100,7 +100,7 @@ for_rule(Rule, Offset, PrevDSTOffset, NextDSTOffset, Year) ->
{WT,ST,UT}= for_rule_old_dst(Rule, Offset, PrevDSTOffset, Year),
WTNew= add_offset(WT, PrevDSTOffset, NextDSTOffset),
{{WT,WTNew}, ST, UT}.
@@ -166,7 +166,7 @@ add_offset(Datetime, FromOffset, ToOffset) ->
% returns {WallTime, StdTime, UtcTime}
% returns {WallTime, StdTime, UtcTime}
% where each is a datetime tuple: {{Y,M,D}{HH,MM,SS}}
@@ -175,7 +175,7 @@ all_times(X,_,_) when is_atom(X) ->
{X,X,X};
% universal time given
all_times({Date, #tztime{time=UTCTime, flag=Flag}}, Offset, DSTOffset)
all_times({Date, #tztime{time=UTCTime, flag=Flag}}, Offset, DSTOffset)
when Flag=:=u; Flag=:=g; Flag=:=z ->
UTCDatetime= {Date, UTCTime},
@@ -202,7 +202,7 @@ all_times({Date, #tztime{time=STDTime, flag=s}}, Offset, DSTOffset) ->
% wall time given
all_times({Date, #tztime{time=WallTime, flag=Flag}}, Offset, DSTOffset)
all_times({Date, #tztime{time=WallTime, flag=Flag}}, Offset, DSTOffset)
when Flag=:=w; Flag=:=undefined ->
WallDatetime= {Date, WallTime},
@@ -236,21 +236,21 @@ compare(_, X) when X=:=min; X=:=minimum ->
% returns true if DT1 =< DT2. False otherwise. can be used with lists:sort/2
% both times are assumed to be in the same zone/DST context
compare(DT1={{Y1,M1,D1},{HH1,MM1,SS1}}, DT2={{Y2,M2,D2},{HH2,MM2,SS2}})
compare(DT1={{Y1,M1,D1},{HH1,MM1,SS1}}, DT2={{Y2,M2,D2},{HH2,MM2,SS2}})
when is_integer(Y1), is_integer(Y2)
, is_integer(M1), is_integer(M2)
, is_integer(D1), is_integer(D2)
, is_integer(HH1), is_integer(HH2)
, is_integer(MM1), is_integer(MM2)
, is_integer(SS1), is_integer(SS2)
, is_integer(M1), is_integer(M2)
, is_integer(D1), is_integer(D2)
, is_integer(HH1), is_integer(HH2)
, is_integer(MM1), is_integer(MM2)
, is_integer(SS1), is_integer(SS2)
->
DT1 =< DT2;
compare({Date1, #tztime{time=Time1, flag=F}}
, {Date2, #tztime{time=Time2, flag=F}}) ->
Date1 =< Date2 orelse Time1 =< Time2;
compare(X,Y) ->
@@ -284,7 +284,7 @@ first_day_limited(Day, {geq, N}, Y,M) ->
next_day(Day, {Y,M,N});
first_day_limited(Day, {leq, N}, Y,M) ->
previous_day(Day, {Y,M,N}).
% Returns the soonest date on which Day (sun/mon/tue/etc.) occurs BEFORE the given date.
@@ -294,7 +294,7 @@ previous_day(Day, Date) ->
LeqDoW= calendar:day_of_the_week(Date),
case Daynum=:=LeqDoW of
true -> Date;
_ ->
_ ->
DayDiff= day_diff(LeqDoW, Daynum),
add_days_in_month(-DayDiff, Date)
end.
@@ -307,7 +307,7 @@ next_day(Day, Date) ->
LeqDoW= calendar:day_of_the_week(Date),
case Daynum=:=LeqDoW of
true -> Date;
_ ->
_ ->
DayDiff= day_diff(Daynum, LeqDoW),
add_days_in_month(DayDiff, Date)
end.
@@ -320,28 +320,28 @@ day_diff(From, To) ->
true -> From - To + 7;
_ -> From - To
end.
% adds/subtracts days within a month
% errors-out if arguments require change of month
add_days_in_month(Days, Date={Y,M,D}) ->
case D+Days < 1 of
true -> erlang:error(no_previous_day, {Days, Date});
_ ->
_ ->
case D+Days > calendar:last_day_of_the_month(Y,M) of
true -> erlang:error(no_next_day, {Days, Date});
_ -> {Y,M,D+Days}
end
end.
%% subtracts 1 second from a single datetime
% @todo type checking
m1s(Date= {{Y,M,D},{HH,MM,SS}})
m1s(Date= {{Y,M,D},{HH,MM,SS}})
when is_integer(Y), is_integer(M), is_integer(D)
, is_integer(HH), is_integer(MM), is_integer(SS) ->
calendar:gregorian_seconds_to_datetime(calendar:datetime_to_gregorian_seconds(Date) - 1);
%% subtracts 1 second from all datetimes
@@ -353,7 +353,7 @@ m1s({WD, SD, UD}) ->
% @todo type checking
m1s(W,S,U) when is_tuple(W), is_tuple(S), is_tuple(U) ->
{m1s(W), m1s(S), m1s(U)}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@@ -76,7 +76,7 @@ get_implementation() ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% GEN_SERVER
%% GEN_SERVER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -85,7 +85,7 @@ start_link(StartArgs) ->
%% TODO: create a db behavior
init(DbModule) when DbModule =:= ezic_db_mnesia;
init(DbModule) when DbModule =:= ezic_db_mnesia;
DbModule=:= ezic_db_ets ->
DbModule:init(),
State = #state{mod = DbModule},

View File

@@ -53,8 +53,8 @@ get_all(Tab) ->
try ets:lookup(Tab, Tab) of X -> X
catch error:X -> {error, X}
end.
insert_all(Records) ->
@@ -77,7 +77,7 @@ wipe(Tab) ->
init() ->
{ok, DbDir}= application:get_env(db_dir),
Filename= filename:join(DbDir, ?DB_FILENAME),
case db_sane(Filename) of
case db_sane(Filename) of
true -> load_tabfile(Filename);
false -> create_tables(Filename)
end,
@@ -96,7 +96,7 @@ db_sane(Filename) ->
{ok, _} -> true;
{error, _} -> false
end.
%% creates the dets table and populates it.

View File

@@ -18,7 +18,7 @@
]).
-define(create(Record),
{atomic, ok} = mnesia:create_table(Record,
{atomic, ok} = mnesia:create_table(Record,
[{type, bag}
, {disc_copies, [node()]}
, {attributes, record_info(fields, Record)}
@@ -41,7 +41,7 @@ zones(Name) ->
end,
{atomic, Zones}= mnesia:transaction(F),
Zones.
% retrieve all rules by name
rules(Name) ->
F = fun()->
@@ -50,7 +50,7 @@ rules(Name) ->
end,
{atomic, Rules}= mnesia:transaction(F),
Rules.
% retrieve all flatzones by tz name
flatzones(Name) ->
F = fun()->
@@ -59,7 +59,7 @@ flatzones(Name) ->
end,
{atomic, FlatZones}= mnesia:transaction(F),
FlatZones.
% get all records from table
get_all(Tab) when is_atom(Tab) ->
F = fun() ->
@@ -96,7 +96,7 @@ flatzone(Date, TzName) ->
_ ->
erlang:error(should_not_happen, {FlatZones, Date, TzName})
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@@ -26,7 +26,7 @@ flatten(Zones, AllRules) ->
contains_date(FlatZone, Date) ->
NDate= ezic_date:normalize(Date),
contains_date2(FlatZone, NDate).
%% create matchspec for the given date and name
%% date is expected to have a tztime with accurate flag
@@ -79,7 +79,7 @@ flatten_all_zones([Z1|_]= AllZones, AllRules, FlatZones) ->
contains_date2(#flatzone{utc_from=From, utc_to=To}, {Dt,#tztime{time=T, flag=F}})
contains_date2(#flatzone{utc_from=From, utc_to=To}, {Dt,#tztime{time=T, flag=F}})
when F=:= u; F=:= g; F=:=z ->
Date={Dt, T},
ezic_date:compare(From, Date) andalso ezic_date:compare(Date, To);
@@ -87,12 +87,12 @@ contains_date2(#flatzone{utc_from=From, utc_to=To}, {Dt,#tztime{time=T, flag=F}}
contains_date2(#flatzone{std_from=From, std_to=To}, {Dt,#tztime{time=T, flag=s}}) ->
Date={Dt, T},
ezic_date:compare(From, Date) andalso ezic_date:compare(Date, To);
contains_date2(#flatzone{wall_from=From, wall_to=To}, {Dt,#tztime{time=T, flag=F}})
when F=:=w; F=:=undefined ->
Date={Dt, T},
ezic_date:compare(From, Date) andalso ezic_date:compare(Date, To).
@@ -122,7 +122,7 @@ flatten_zone_set(FromTimeStub=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset}
%% ?debugVal(Zone),
%% we have a flatzone with start times;
%% we have a flatzone with start times;
%% must populate the base gmt offset and name for the current zone
FromTime= populate_flatzone(FromTimeStub, Zone),
@@ -133,9 +133,9 @@ flatten_zone_set(FromTimeStub=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset}
%% @todo see if dst rules carry over zone changes IRL. This
%% assumes they don't.
%% gather all rules that _may_ apply
%% gather all rules that _may_ apply
Rules= [R || R <- AllRules, R#rule.name =:= RuleName ],
Rules= [R || R <- AllRules, R#rule.name =:= RuleName ],
%% ?debugVal(FromTime),
%% ?debugVal(Rules),
@@ -149,16 +149,16 @@ flatten_zone_set(FromTimeStub=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset}
%% ?debugVal(FinalFlats),
%% ?debugVal(NextFlat),
%% return flats if we've exceeded our years, or recurse if we can keep going
NFUTCFrom = NextFlat#flatzone.utc_from,
try maxyear_reached(NFUTCFrom) of
true ->
true ->
%% ?debugMsg("maxyear reached from flatten_zone_set"),
FinalFlats;
false ->
false ->
flatten_zone_set(NextFlat, RestZones, AllRules, FinalFlats, EndingRule)
catch
catch
exit:Reason ->
%% ?debugMsg("bad year for nextflat:"),
%% ?debugVal(NextFlat),
@@ -178,21 +178,21 @@ flatten_rule_set(FlatStart=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset, offs
ValidRules= lists:delete(CurrentRule, Rules),
RulesWithDates= lists:foldl(
fun(R, Acc)->
fun(R, Acc)->
case ezic_rule:project_next(R, Offset, DSTOffset, UTCFrom) of
none -> Acc;
{Year, D} -> [{D,Year, R} | Acc]
end
end
,[], ValidRules),
{UTCEndingRuleDate, EndingRuleYear, EndingRule}=
{UTCEndingRuleDate, EndingRuleYear, EndingRule}=
case length(RulesWithDates) > 0 of
false -> {maximum, maximum, none};
true -> hd(lists:sort(RulesWithDates))
end,
ZoneDate= ezic_zone:project_end_utc(Zone, DSTOffset),
@@ -201,9 +201,9 @@ flatten_rule_set(FlatStart=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset, offs
%% ?debugVal(EndingRule),
%% ?debugVal(ZoneDate),
try maxyear_reached(UTCEndingRuleDate) andalso maxyear_reached(ZoneDate) of
true ->
true ->
%% ?debugMsg("maxyear reached from flatten_rule_set"),
{EndFlat, NextFlat}= finish_and_start_flat(max_year, FlatStart, DSTOffset),
NewFlats= [EndFlat | Flats],
@@ -211,7 +211,7 @@ flatten_rule_set(FlatStart=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset, offs
false ->
case ezic_date:compare(ZoneDate, UTCEndingRuleDate) of
false ->
false ->
%% same zone, new rule
{EndFlat, NextFlat}= finish_and_start_flat(FlatStart, EndingRule, EndingRuleYear),
NewFlats= [EndFlat | Flats],
@@ -242,7 +242,7 @@ flatten_rule_set(FlatStart=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset, offs
finish_and_start_flat(FlatStub=#flatzone{offset=Offset, dstoffset=OldDSTOffset}
, NewRule=#rule{save=NewDSTSave}
, EndingRuleYear) ->
%% @todo for_rule_all was already called in a loop earlier. use those values instead.
{{WD, WDn}, SD, UD}= ezic_date:for_rule(NewRule, Offset, OldDSTOffset, NewDSTSave, EndingRuleYear),
{WDm, SDm, UDm}= ezic_date:m1s({WD, SD, UD}),
@@ -250,7 +250,7 @@ finish_and_start_flat(FlatStub=#flatzone{offset=Offset, dstoffset=OldDSTOffset}
EndFlat= ?ENDFLAT(FlatStub, WDm, SDm, UDm, OldDSTOffset),
NewFlat1= ?FLAT(WDn, SD, UD),
NewFlat2= NewFlat1#flatzone{offset=Offset, dstoffset=NewDSTSave, tzname=EndFlat#flatzone.tzname},
FinalNewFlat= NewFlat2,
%% ?debugVal(EndFlat),
@@ -267,7 +267,7 @@ finish_and_start_flat(FlatStub=#flatzone{}, Zone=#zone{}, EndingDST) ->
EndDatesP1={_,_,UD}= ezic_zone:project_end(Zone, EndingDST),
{WDm, SDm, UDm}= ezic_date:m1s(EndDatesP1),
EndFlat= ?ENDFLAT(FlatStub, WDm, SDm, UDm, EndingDST),
RetNextFlat= #flatzone{dstoffset=EndingDST, utc_from=UD},
%% ?debugVal(EndFlat),
@@ -280,7 +280,7 @@ finish_and_start_flat(max_year, FlatStub, DSTOffset) ->
Stop= {{?MAXYEAR+1,1,1},{0,0,0}},
NextFlat= #flatzone{utc_from=Stop},
{EndFlat, NextFlat}.
%% both timezone and rule are ending at the same time
@@ -325,7 +325,7 @@ ms_guards(s, D) ->
ms_guards2(D, '$3', '$4');
ms_guards(X, D) when X=:=w;X=:=undefined ->
ms_guards2(D, '$1', '$2').
ms_guards2(D, From, To) ->
[

View File

@@ -16,14 +16,14 @@ load() ->
%% returns all records, parsed from the tzdata files in directory Dir.
load(Dir) ->
{ok, Records} =
{ok, Records} =
case filelib:is_dir(Dir) of
true -> {ok, parse_dir(Dir)};
false -> erlang:error({not_a_directory, Dir})
end,
Records.
@@ -89,7 +89,7 @@ clean_line(Line) ->
Line1= string:strip(Line),
Line2= string:strip(Line1, both, $\n),
Line3= string:strip(Line2, both, $\t),
%% remove comments and returns
FinalLine=Line3,
CPos= string:chr(FinalLine, $#),

View File

@@ -21,7 +21,7 @@ year("max") -> maximum;
year("only") -> only;
year(X) ->
list_to_integer(X).
% X=last(Mon,Tue,Wed,...,Sun) -> {last, (Mon,Tue,Web,...,Sun)}
@@ -43,7 +43,7 @@ day_pattern(X=[D,A,Y, Sign,$= | IntS]) ->
% X=int()
day_pattern(X) ->
list_to_integer(X).
@@ -134,7 +134,7 @@ sign($<) -> {ok, leq}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INTERNAL
% INTERNAL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -154,9 +154,9 @@ tz_abbr(Format, 0) ->
tz_abbr(Format, Pos) ->
First=string:substr(Format, 1, Pos-1),
Last=string:substr(Format, Pos+2),
string:concat(First, [$~, $s|Last]).
string:concat(First, [$~, $s|Last]).

View File

@@ -32,5 +32,5 @@ separate(Records) ->
Leaps= [Z || Z=#leap{} <- Records],
Links= [Z || Z=#link{} <- Records],
{ok, Zones, Rules, Leaps, Links}.

View File

@@ -16,10 +16,10 @@ parse([Name,FromS,ToS,_Type,InS,OnS,AtS,SaveS,Letters]) ->
In= ezic_date:month_to_num(InS),
On= ezic_parse:day_pattern(OnS),
At= ezic_parse:time(AtS),
Save= ezic_parse:time_val(SaveS),
Rule= #rule{name=Name, from=From, to=To, type=not_done,
Rule= #rule{name=Name, from=From, to=To, type=not_done,
in=In, on=On, at=At, save=Save, letters=Letters},
{ok, Rule}.
@@ -63,7 +63,7 @@ years_after(Y, {_From, To}) when Y > To ->
years_after(Y, {From, To}) ->
{erlang:max(Y,From), To}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INTERNAL
@@ -76,7 +76,7 @@ project_next2(Rule, Offset, UTCAfter, DSTOffset, Years={FromYear, _}) ->
RuleDate= ezic_date:for_rule_utc(Rule, Offset, DSTOffset, FromYear),
case ezic_date:compare(UTCAfter, RuleDate) andalso (not ezic_date:equal(UTCAfter, RuleDate)) of
true -> {FromYear, RuleDate};
false ->
false ->
RestYears= years_after(FromYear+1, Years),
project_next2(Rule, Offset, UTCAfter, DSTOffset, RestYears)
end.

View File

@@ -1,7 +1,7 @@
%%%-------------------------------------------------------------------
%%% File : ezic_sup.erl
%%% Author : aj <aj@fattie>
%%% Description :
%%% Description :
%%%
%%% Created : 15 Nov 2010 by aj <aj@fattie>
%%%-------------------------------------------------------------------
@@ -34,9 +34,9 @@ start_link(StartArgs) ->
%% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
%% ignore |
%% {error, Reason}
%% Description: Whenever a supervisor is started using
%% supervisor:start_link/[2,3], this function is called by the new process
%% to find out about restart strategy, maximum restart frequency and child
%% Description: Whenever a supervisor is started using
%% supervisor:start_link/[2,3], this function is called by the new process
%% to find out about restart strategy, maximum restart frequency and child
%% specifications.
%%--------------------------------------------------------------------
init(StartArgs) ->

View File

@@ -22,7 +22,7 @@ parse([Name,GmtOffS,Rule,FormatS | UntilTokens]) ->
GmtOff= ezic_parse:time_val(GmtOffS),
Until = ezic_parse:until(UntilTokens),
Format= ezic_parse:tz_abbr(FormatS),
{ok, #zone{
name=Name, gmtoff=GmtOff, rule=Rule,
format=Format, until=Until
@@ -46,11 +46,11 @@ get_zone_utc(_, []) ->
erlang:error(no_current);
get_zone_utc(_UTCDatetime, _Zones) ->
not_done.
% returns {[SimilarZone], [DifferentZone]}
% 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) ->
@@ -72,7 +72,6 @@ offset_sec(Zone) ->
% returns ALL datetimes projected for zone end (given current DST Offset)
project_end(#zone{until=Until, gmtoff=Offset}, DSTOffset) ->
NUntil= ezic_date:normalize(Until),
@@ -84,20 +83,20 @@ project_end_utc(Zone=#zone{}, DSTOffset) ->
% ?debugVal(Zone),
{_,_,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).
%% 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),

View File

@@ -5,30 +5,30 @@
project_next_test_() ->
[
% simple UTC example
?_assertEqual({2010, {{2010,11,10},{16,20,0}}},
?_assertEqual({2010, {{2010,11,10},{16,20,0}}},
ezic_rule:project_next(
#rule{from=1984, to=2032, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
, {-5,0,0}, {-1,0,0}, {{2010,11,10},{0,0,0}}
))
% skip a year UTC example
, ?_assertEqual({2011, {{2011,11,10},{16,20,0}}},
, ?_assertEqual({2011, {{2011,11,10},{16,20,0}}},
ezic_rule:project_next(
#rule{from=1984, to=2032, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
, {-5,0,0}, {-1,0,0}, {{2010,11,10},{16,21,0}}
))
% skip 3 years UTC example
, ?_assertEqual({2013, {{2013,11,10},{16,20,0}}},
, ?_assertEqual({2013, {{2013,11,10},{16,20,0}}},
ezic_rule:project_next(
#rule{from=1984, to=2032, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
, {-5,0,0}, {-1,0,0}, {{2012,11,11},{16,20,0}}
))
% no solution
, ?_assertEqual(none,
, ?_assertEqual(none,
ezic_rule:project_next(
#rule{from=1984, to=2010, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
, {-5,0,0}, {-1,0,0}, {{2012,11,11},{16,20,0}}

View File

@@ -17,17 +17,17 @@ split_by_name_test_() ->
project_end_utc_test_() ->
[
?_assertEqual({{2010,11,10},{16,20,0}},
?_assertEqual({{2010,11,10},{16,20,0}},
ezic_zone:project_end_utc(
#zone{until={{2010,11,10},#tztime{time={10,20,0}, flag=w}}, gmtoff={-7,0,0}}
, {1,0,0}))
, ?_assertEqual({{2010,11,10},{16,20,0}},
, ?_assertEqual({{2010,11,10},{16,20,0}},
ezic_zone:project_end_utc(
#zone{until={{2010,11,10},#tztime{time={9,20,0}, flag=s}}, gmtoff={-7,0,0}}
, {1,0,0}))
, ?_assertEqual({{2010,11,10},{16,20,0}},
, ?_assertEqual({{2010,11,10},{16,20,0}},
ezic_zone:project_end_utc(
#zone{until={{2010,11,10},#tztime{time={16,20,0}, flag=u}}, gmtoff={-7,0,0}}
, {1,0,0}))
@@ -46,11 +46,11 @@ next_datetime_test_() ->
Z1=BZ#zone{until={{2010,11,15},#tztime{}}}
, Z2=BZ#zone{until={{2010,11,5},#tztime{}}}
, Z3=BZ#zone{until={{2010,11,25},#tztime{}}}
, Zt1=BZ#zone{until={{2010,11,5},#tztime{time={5,0,0}, flag=u}}}
, Zt2=BZ#zone{until={{2010,11,5},#tztime{time={12,0,0}, flag=u}}}
, Zt3=BZ#zone{until={{2010,11,5},#tztime{time={17,0,0}, flag=u}}}
, Zy1=BZ#zone{until={{1978,11,5},#tztime{}}}
, Zy2=BZ#zone{until={{1979,11,5},#tztime{}}}
, Zy3=BZ#zone{until={{1980,11,5},#tztime{}}}