Removes extra whitespace at EOL
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
ezic
|
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.
|
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
|
Example Setup
|
||||||
-----
|
-----
|
||||||
|
|
||||||
# setup your local environment
|
# setup your local environment
|
||||||
mkdir -p priv/tzdata
|
mkdir -p priv/tzdata
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ Example Setup
|
|||||||
# remove a few troublesome files
|
# remove a few troublesome files
|
||||||
cd priv/tzdata
|
cd priv/tzdata
|
||||||
rm *.sh *.gz *.tab factory Makefile
|
rm *.sh *.gz *.tab factory Makefile
|
||||||
|
|
||||||
# build and run ezic
|
# build and run ezic
|
||||||
cd -
|
cd -
|
||||||
make all run
|
make all run
|
||||||
@@ -63,7 +63,7 @@ This project is in the [public domain](http://en.wikipedia.org/wiki/Public_Domai
|
|||||||
Contributed Code
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ make_app([AppDirAtom]) ->
|
|||||||
%% folder (assuming OTP directory structure)
|
%% folder (assuming OTP directory structure)
|
||||||
get_modules(AppDir) ->
|
get_modules(AppDir) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
fun(X)-> filename:basename(X, ".erl") end,
|
fun(X)-> filename:basename(X, ".erl") end,
|
||||||
filelib:wildcard(
|
filelib:wildcard(
|
||||||
filename:join([AppDir, "src", "*.erl"])
|
filename:join([AppDir, "src", "*.erl"])
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
{registered, []},
|
{registered, []},
|
||||||
{vsn, "0.2.0"},
|
{vsn, "0.2.0"},
|
||||||
{applications, [
|
{applications, [
|
||||||
kernel,
|
kernel,
|
||||||
stdlib
|
stdlib
|
||||||
]},
|
]},
|
||||||
{mod, {ezic_app, ezic_db_ets}},
|
{mod, {ezic_app, ezic_db_ets}},
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ localtime(TzName) ->
|
|||||||
utc_to_local(UTCDatetime, TzName) ->
|
utc_to_local(UTCDatetime, TzName) ->
|
||||||
NormalDatetime= ezic_date:normalize(UTCDatetime, u),
|
NormalDatetime= ezic_date:normalize(UTCDatetime, u),
|
||||||
utc_to_local_handleFlatzone(UTCDatetime, ezic_db:flatzone(NormalDatetime, TzName)).
|
utc_to_local_handleFlatzone(UTCDatetime, ezic_db:flatzone(NormalDatetime, TzName)).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% returns utc time for corresponding time in given timezone utc
|
%% returns utc time for corresponding time in given timezone utc
|
||||||
local_to_utc(LocalDatetime, TzName) ->
|
local_to_utc(LocalDatetime, TzName) ->
|
||||||
NormalDatetime= ezic_date:normalize(LocalDatetime, w),
|
NormalDatetime= ezic_date:normalize(LocalDatetime, w),
|
||||||
local_to_utc_handleFlatzone(LocalDatetime, ezic_db:flatzone(NormalDatetime, TzName)).
|
local_to_utc_handleFlatzone(LocalDatetime, ezic_db:flatzone(NormalDatetime, TzName)).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
%%% File : ezic_app.erl
|
%%% File : ezic_app.erl
|
||||||
%%% Author : aj <aj@fattie>
|
%%% Author : aj <aj@fattie>
|
||||||
%%% Description :
|
%%% Description :
|
||||||
%%%
|
%%%
|
||||||
%%% Created : 15 Nov 2010 by aj <aj@fattie>
|
%%% Created : 15 Nov 2010 by aj <aj@fattie>
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
%% Function: start(Type, StartArgs) -> {ok, Pid} |
|
%% Function: start(Type, StartArgs) -> {ok, Pid} |
|
||||||
%% {ok, Pid, State} |
|
%% {ok, Pid, State} |
|
||||||
%% {error, Reason}
|
%% {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
|
%% is started using application:start/1,2, and should start the processes
|
||||||
%% of the application. If the application is structured according to the
|
%% of the application. If the application is structured according to the
|
||||||
%% OTP design principles as a supervision tree, this means starting the
|
%% OTP design principles as a supervision tree, this means starting the
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
start(_Type, StartArgs) ->
|
start(_Type, StartArgs) ->
|
||||||
case ezic_sup:start_link(StartArgs) of
|
case ezic_sup:start_link(StartArgs) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
{ok, Pid};
|
{ok, Pid};
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
@@ -37,7 +37,7 @@ start(_Type, StartArgs) ->
|
|||||||
%% Function: stop(State) -> void()
|
%% Function: stop(State) -> void()
|
||||||
%% Description: This function is called whenever an application
|
%% Description: This function is called whenever an application
|
||||||
%% has stopped. It is intended to be the opposite of Module:start/2 and
|
%% 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) ->
|
stop(_State) ->
|
||||||
ok.
|
ok.
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ normalize({{Y,M,D}, T={_,_,_}}) ->
|
|||||||
%% normalizes a date, and sets the #tztime{flag=Flag} if appropriate
|
%% normalizes a date, and sets the #tztime{flag=Flag} if appropriate
|
||||||
%% @todo ensure flag is valid
|
%% @todo ensure flag is valid
|
||||||
%% @todo cover all the cases. this is currently just used for standard erlang datetimes
|
%% @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) ->
|
when is_atom(Flag), is_integer(HH) ->
|
||||||
|
|
||||||
DTz= {D, #tztime{time=T, flag=Flag}},
|
DTz= {D, #tztime{time=T, flag=Flag}},
|
||||||
normalize(DTz);
|
normalize(DTz);
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ normalize(D, Flag) ->
|
|||||||
_ ->
|
_ ->
|
||||||
erlang:error(badDateTime, D)
|
erlang:error(badDateTime, D)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ for_rule(Rule, Offset, PrevDSTOffset, NextDSTOffset, Year) ->
|
|||||||
{WT,ST,UT}= for_rule_old_dst(Rule, Offset, PrevDSTOffset, Year),
|
{WT,ST,UT}= for_rule_old_dst(Rule, Offset, PrevDSTOffset, Year),
|
||||||
WTNew= add_offset(WT, PrevDSTOffset, NextDSTOffset),
|
WTNew= add_offset(WT, PrevDSTOffset, NextDSTOffset),
|
||||||
{{WT,WTNew}, ST, UT}.
|
{{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}}
|
% 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};
|
{X,X,X};
|
||||||
|
|
||||||
% universal time given
|
% 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 ->
|
when Flag=:=u; Flag=:=g; Flag=:=z ->
|
||||||
UTCDatetime= {Date, UTCTime},
|
UTCDatetime= {Date, UTCTime},
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ all_times({Date, #tztime{time=STDTime, flag=s}}, Offset, DSTOffset) ->
|
|||||||
|
|
||||||
|
|
||||||
% wall time given
|
% 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 ->
|
when Flag=:=w; Flag=:=undefined ->
|
||||||
WallDatetime= {Date, WallTime},
|
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
|
% 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
|
% 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)
|
when is_integer(Y1), is_integer(Y2)
|
||||||
, is_integer(M1), is_integer(M2)
|
, is_integer(M1), is_integer(M2)
|
||||||
, is_integer(D1), is_integer(D2)
|
, is_integer(D1), is_integer(D2)
|
||||||
, is_integer(HH1), is_integer(HH2)
|
, is_integer(HH1), is_integer(HH2)
|
||||||
, is_integer(MM1), is_integer(MM2)
|
, is_integer(MM1), is_integer(MM2)
|
||||||
, is_integer(SS1), is_integer(SS2)
|
, is_integer(SS1), is_integer(SS2)
|
||||||
->
|
->
|
||||||
|
|
||||||
DT1 =< DT2;
|
DT1 =< DT2;
|
||||||
|
|
||||||
|
|
||||||
compare({Date1, #tztime{time=Time1, flag=F}}
|
compare({Date1, #tztime{time=Time1, flag=F}}
|
||||||
, {Date2, #tztime{time=Time2, flag=F}}) ->
|
, {Date2, #tztime{time=Time2, flag=F}}) ->
|
||||||
|
|
||||||
Date1 =< Date2 orelse Time1 =< Time2;
|
Date1 =< Date2 orelse Time1 =< Time2;
|
||||||
|
|
||||||
compare(X,Y) ->
|
compare(X,Y) ->
|
||||||
@@ -284,7 +284,7 @@ first_day_limited(Day, {geq, N}, Y,M) ->
|
|||||||
next_day(Day, {Y,M,N});
|
next_day(Day, {Y,M,N});
|
||||||
first_day_limited(Day, {leq, N}, Y,M) ->
|
first_day_limited(Day, {leq, N}, Y,M) ->
|
||||||
previous_day(Day, {Y,M,N}).
|
previous_day(Day, {Y,M,N}).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
% Returns the soonest date on which Day (sun/mon/tue/etc.) occurs BEFORE the given date.
|
% 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),
|
LeqDoW= calendar:day_of_the_week(Date),
|
||||||
case Daynum=:=LeqDoW of
|
case Daynum=:=LeqDoW of
|
||||||
true -> Date;
|
true -> Date;
|
||||||
_ ->
|
_ ->
|
||||||
DayDiff= day_diff(LeqDoW, Daynum),
|
DayDiff= day_diff(LeqDoW, Daynum),
|
||||||
add_days_in_month(-DayDiff, Date)
|
add_days_in_month(-DayDiff, Date)
|
||||||
end.
|
end.
|
||||||
@@ -307,7 +307,7 @@ next_day(Day, Date) ->
|
|||||||
LeqDoW= calendar:day_of_the_week(Date),
|
LeqDoW= calendar:day_of_the_week(Date),
|
||||||
case Daynum=:=LeqDoW of
|
case Daynum=:=LeqDoW of
|
||||||
true -> Date;
|
true -> Date;
|
||||||
_ ->
|
_ ->
|
||||||
DayDiff= day_diff(Daynum, LeqDoW),
|
DayDiff= day_diff(Daynum, LeqDoW),
|
||||||
add_days_in_month(DayDiff, Date)
|
add_days_in_month(DayDiff, Date)
|
||||||
end.
|
end.
|
||||||
@@ -320,28 +320,28 @@ day_diff(From, To) ->
|
|||||||
true -> From - To + 7;
|
true -> From - To + 7;
|
||||||
_ -> From - To
|
_ -> From - To
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
% adds/subtracts days within a month
|
% adds/subtracts days within a month
|
||||||
% errors-out if arguments require change of month
|
% errors-out if arguments require change of month
|
||||||
add_days_in_month(Days, Date={Y,M,D}) ->
|
add_days_in_month(Days, Date={Y,M,D}) ->
|
||||||
case D+Days < 1 of
|
case D+Days < 1 of
|
||||||
true -> erlang:error(no_previous_day, {Days, Date});
|
true -> erlang:error(no_previous_day, {Days, Date});
|
||||||
_ ->
|
_ ->
|
||||||
case D+Days > calendar:last_day_of_the_month(Y,M) of
|
case D+Days > calendar:last_day_of_the_month(Y,M) of
|
||||||
true -> erlang:error(no_next_day, {Days, Date});
|
true -> erlang:error(no_next_day, {Days, Date});
|
||||||
_ -> {Y,M,D+Days}
|
_ -> {Y,M,D+Days}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% subtracts 1 second from a single datetime
|
%% subtracts 1 second from a single datetime
|
||||||
% @todo type checking
|
% @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)
|
when is_integer(Y), is_integer(M), is_integer(D)
|
||||||
, is_integer(HH), is_integer(MM), is_integer(SS) ->
|
, is_integer(HH), is_integer(MM), is_integer(SS) ->
|
||||||
|
|
||||||
calendar:gregorian_seconds_to_datetime(calendar:datetime_to_gregorian_seconds(Date) - 1);
|
calendar:gregorian_seconds_to_datetime(calendar:datetime_to_gregorian_seconds(Date) - 1);
|
||||||
|
|
||||||
%% subtracts 1 second from all datetimes
|
%% subtracts 1 second from all datetimes
|
||||||
@@ -353,7 +353,7 @@ m1s({WD, SD, UD}) ->
|
|||||||
% @todo type checking
|
% @todo type checking
|
||||||
m1s(W,S,U) when is_tuple(W), is_tuple(S), is_tuple(U) ->
|
m1s(W,S,U) when is_tuple(W), is_tuple(S), is_tuple(U) ->
|
||||||
{m1s(W), m1s(S), m1s(U)}.
|
{m1s(W), m1s(S), m1s(U)}.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ get_implementation() ->
|
|||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%% GEN_SERVER
|
%% GEN_SERVER
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ start_link(StartArgs) ->
|
|||||||
|
|
||||||
|
|
||||||
%% TODO: create a db behavior
|
%% TODO: create a db behavior
|
||||||
init(DbModule) when DbModule =:= ezic_db_mnesia;
|
init(DbModule) when DbModule =:= ezic_db_mnesia;
|
||||||
DbModule=:= ezic_db_ets ->
|
DbModule=:= ezic_db_ets ->
|
||||||
DbModule:init(),
|
DbModule:init(),
|
||||||
State = #state{mod = DbModule},
|
State = #state{mod = DbModule},
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ get_all(Tab) ->
|
|||||||
try ets:lookup(Tab, Tab) of X -> X
|
try ets:lookup(Tab, Tab) of X -> X
|
||||||
catch error:X -> {error, X}
|
catch error:X -> {error, X}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
insert_all(Records) ->
|
insert_all(Records) ->
|
||||||
@@ -77,7 +77,7 @@ wipe(Tab) ->
|
|||||||
init() ->
|
init() ->
|
||||||
{ok, DbDir}= application:get_env(db_dir),
|
{ok, DbDir}= application:get_env(db_dir),
|
||||||
Filename= filename:join(DbDir, ?DB_FILENAME),
|
Filename= filename:join(DbDir, ?DB_FILENAME),
|
||||||
case db_sane(Filename) of
|
case db_sane(Filename) of
|
||||||
true -> load_tabfile(Filename);
|
true -> load_tabfile(Filename);
|
||||||
false -> create_tables(Filename)
|
false -> create_tables(Filename)
|
||||||
end,
|
end,
|
||||||
@@ -96,7 +96,7 @@ db_sane(Filename) ->
|
|||||||
{ok, _} -> true;
|
{ok, _} -> true;
|
||||||
{error, _} -> false
|
{error, _} -> false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% creates the dets table and populates it.
|
%% creates the dets table and populates it.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
-define(create(Record),
|
-define(create(Record),
|
||||||
{atomic, ok} = mnesia:create_table(Record,
|
{atomic, ok} = mnesia:create_table(Record,
|
||||||
[{type, bag}
|
[{type, bag}
|
||||||
, {disc_copies, [node()]}
|
, {disc_copies, [node()]}
|
||||||
, {attributes, record_info(fields, Record)}
|
, {attributes, record_info(fields, Record)}
|
||||||
@@ -41,7 +41,7 @@ zones(Name) ->
|
|||||||
end,
|
end,
|
||||||
{atomic, Zones}= mnesia:transaction(F),
|
{atomic, Zones}= mnesia:transaction(F),
|
||||||
Zones.
|
Zones.
|
||||||
|
|
||||||
% retrieve all rules by name
|
% retrieve all rules by name
|
||||||
rules(Name) ->
|
rules(Name) ->
|
||||||
F = fun()->
|
F = fun()->
|
||||||
@@ -50,7 +50,7 @@ rules(Name) ->
|
|||||||
end,
|
end,
|
||||||
{atomic, Rules}= mnesia:transaction(F),
|
{atomic, Rules}= mnesia:transaction(F),
|
||||||
Rules.
|
Rules.
|
||||||
|
|
||||||
% retrieve all flatzones by tz name
|
% retrieve all flatzones by tz name
|
||||||
flatzones(Name) ->
|
flatzones(Name) ->
|
||||||
F = fun()->
|
F = fun()->
|
||||||
@@ -59,7 +59,7 @@ flatzones(Name) ->
|
|||||||
end,
|
end,
|
||||||
{atomic, FlatZones}= mnesia:transaction(F),
|
{atomic, FlatZones}= mnesia:transaction(F),
|
||||||
FlatZones.
|
FlatZones.
|
||||||
|
|
||||||
% get all records from table
|
% get all records from table
|
||||||
get_all(Tab) when is_atom(Tab) ->
|
get_all(Tab) when is_atom(Tab) ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
@@ -96,7 +96,7 @@ flatzone(Date, TzName) ->
|
|||||||
_ ->
|
_ ->
|
||||||
erlang:error(should_not_happen, {FlatZones, Date, TzName})
|
erlang:error(should_not_happen, {FlatZones, Date, TzName})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ flatten(Zones, AllRules) ->
|
|||||||
contains_date(FlatZone, Date) ->
|
contains_date(FlatZone, Date) ->
|
||||||
NDate= ezic_date:normalize(Date),
|
NDate= ezic_date:normalize(Date),
|
||||||
contains_date2(FlatZone, NDate).
|
contains_date2(FlatZone, NDate).
|
||||||
|
|
||||||
|
|
||||||
%% create matchspec for the given date and name
|
%% create matchspec for the given date and name
|
||||||
%% date is expected to have a tztime with accurate flag
|
%% 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 ->
|
when F=:= u; F=:= g; F=:=z ->
|
||||||
Date={Dt, T},
|
Date={Dt, T},
|
||||||
ezic_date:compare(From, Date) andalso ezic_date:compare(Date, To);
|
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}}) ->
|
contains_date2(#flatzone{std_from=From, std_to=To}, {Dt,#tztime{time=T, flag=s}}) ->
|
||||||
Date={Dt, T},
|
Date={Dt, T},
|
||||||
ezic_date:compare(From, Date) andalso ezic_date:compare(Date, To);
|
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}})
|
contains_date2(#flatzone{wall_from=From, wall_to=To}, {Dt,#tztime{time=T, flag=F}})
|
||||||
when F=:=w; F=:=undefined ->
|
when F=:=w; F=:=undefined ->
|
||||||
Date={Dt, T},
|
Date={Dt, T},
|
||||||
ezic_date:compare(From, Date) andalso ezic_date:compare(Date, To).
|
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),
|
%% ?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
|
%% must populate the base gmt offset and name for the current zone
|
||||||
|
|
||||||
FromTime= populate_flatzone(FromTimeStub, 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
|
%% @todo see if dst rules carry over zone changes IRL. This
|
||||||
%% assumes they don't.
|
%% 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(FromTime),
|
||||||
%% ?debugVal(Rules),
|
%% ?debugVal(Rules),
|
||||||
@@ -149,16 +149,16 @@ flatten_zone_set(FromTimeStub=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset}
|
|||||||
|
|
||||||
%% ?debugVal(FinalFlats),
|
%% ?debugVal(FinalFlats),
|
||||||
%% ?debugVal(NextFlat),
|
%% ?debugVal(NextFlat),
|
||||||
|
|
||||||
%% return flats if we've exceeded our years, or recurse if we can keep going
|
%% return flats if we've exceeded our years, or recurse if we can keep going
|
||||||
NFUTCFrom = NextFlat#flatzone.utc_from,
|
NFUTCFrom = NextFlat#flatzone.utc_from,
|
||||||
try maxyear_reached(NFUTCFrom) of
|
try maxyear_reached(NFUTCFrom) of
|
||||||
true ->
|
true ->
|
||||||
%% ?debugMsg("maxyear reached from flatten_zone_set"),
|
%% ?debugMsg("maxyear reached from flatten_zone_set"),
|
||||||
FinalFlats;
|
FinalFlats;
|
||||||
false ->
|
false ->
|
||||||
flatten_zone_set(NextFlat, RestZones, AllRules, FinalFlats, EndingRule)
|
flatten_zone_set(NextFlat, RestZones, AllRules, FinalFlats, EndingRule)
|
||||||
catch
|
catch
|
||||||
exit:Reason ->
|
exit:Reason ->
|
||||||
%% ?debugMsg("bad year for nextflat:"),
|
%% ?debugMsg("bad year for nextflat:"),
|
||||||
%% ?debugVal(NextFlat),
|
%% ?debugVal(NextFlat),
|
||||||
@@ -178,21 +178,21 @@ flatten_rule_set(FlatStart=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset, offs
|
|||||||
|
|
||||||
ValidRules= lists:delete(CurrentRule, Rules),
|
ValidRules= lists:delete(CurrentRule, Rules),
|
||||||
RulesWithDates= lists:foldl(
|
RulesWithDates= lists:foldl(
|
||||||
fun(R, Acc)->
|
fun(R, Acc)->
|
||||||
case ezic_rule:project_next(R, Offset, DSTOffset, UTCFrom) of
|
case ezic_rule:project_next(R, Offset, DSTOffset, UTCFrom) of
|
||||||
none -> Acc;
|
none -> Acc;
|
||||||
{Year, D} -> [{D,Year, R} | Acc]
|
{Year, D} -> [{D,Year, R} | Acc]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
,[], ValidRules),
|
,[], ValidRules),
|
||||||
|
|
||||||
|
|
||||||
{UTCEndingRuleDate, EndingRuleYear, EndingRule}=
|
|
||||||
|
{UTCEndingRuleDate, EndingRuleYear, EndingRule}=
|
||||||
case length(RulesWithDates) > 0 of
|
case length(RulesWithDates) > 0 of
|
||||||
false -> {maximum, maximum, none};
|
false -> {maximum, maximum, none};
|
||||||
true -> hd(lists:sort(RulesWithDates))
|
true -> hd(lists:sort(RulesWithDates))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
ZoneDate= ezic_zone:project_end_utc(Zone, DSTOffset),
|
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(EndingRule),
|
||||||
%% ?debugVal(ZoneDate),
|
%% ?debugVal(ZoneDate),
|
||||||
|
|
||||||
|
|
||||||
try maxyear_reached(UTCEndingRuleDate) andalso maxyear_reached(ZoneDate) of
|
try maxyear_reached(UTCEndingRuleDate) andalso maxyear_reached(ZoneDate) of
|
||||||
true ->
|
true ->
|
||||||
%% ?debugMsg("maxyear reached from flatten_rule_set"),
|
%% ?debugMsg("maxyear reached from flatten_rule_set"),
|
||||||
{EndFlat, NextFlat}= finish_and_start_flat(max_year, FlatStart, DSTOffset),
|
{EndFlat, NextFlat}= finish_and_start_flat(max_year, FlatStart, DSTOffset),
|
||||||
NewFlats= [EndFlat | Flats],
|
NewFlats= [EndFlat | Flats],
|
||||||
@@ -211,7 +211,7 @@ flatten_rule_set(FlatStart=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset, offs
|
|||||||
false ->
|
false ->
|
||||||
|
|
||||||
case ezic_date:compare(ZoneDate, UTCEndingRuleDate) of
|
case ezic_date:compare(ZoneDate, UTCEndingRuleDate) of
|
||||||
false ->
|
false ->
|
||||||
%% same zone, new rule
|
%% same zone, new rule
|
||||||
{EndFlat, NextFlat}= finish_and_start_flat(FlatStart, EndingRule, EndingRuleYear),
|
{EndFlat, NextFlat}= finish_and_start_flat(FlatStart, EndingRule, EndingRuleYear),
|
||||||
NewFlats= [EndFlat | Flats],
|
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}
|
finish_and_start_flat(FlatStub=#flatzone{offset=Offset, dstoffset=OldDSTOffset}
|
||||||
, NewRule=#rule{save=NewDSTSave}
|
, NewRule=#rule{save=NewDSTSave}
|
||||||
, EndingRuleYear) ->
|
, EndingRuleYear) ->
|
||||||
|
|
||||||
%% @todo for_rule_all was already called in a loop earlier. use those values instead.
|
%% @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),
|
{{WD, WDn}, SD, UD}= ezic_date:for_rule(NewRule, Offset, OldDSTOffset, NewDSTSave, EndingRuleYear),
|
||||||
{WDm, SDm, UDm}= ezic_date:m1s({WD, SD, UD}),
|
{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),
|
EndFlat= ?ENDFLAT(FlatStub, WDm, SDm, UDm, OldDSTOffset),
|
||||||
NewFlat1= ?FLAT(WDn, SD, UD),
|
NewFlat1= ?FLAT(WDn, SD, UD),
|
||||||
NewFlat2= NewFlat1#flatzone{offset=Offset, dstoffset=NewDSTSave, tzname=EndFlat#flatzone.tzname},
|
NewFlat2= NewFlat1#flatzone{offset=Offset, dstoffset=NewDSTSave, tzname=EndFlat#flatzone.tzname},
|
||||||
|
|
||||||
FinalNewFlat= NewFlat2,
|
FinalNewFlat= NewFlat2,
|
||||||
|
|
||||||
%% ?debugVal(EndFlat),
|
%% ?debugVal(EndFlat),
|
||||||
@@ -267,7 +267,7 @@ finish_and_start_flat(FlatStub=#flatzone{}, Zone=#zone{}, EndingDST) ->
|
|||||||
EndDatesP1={_,_,UD}= ezic_zone:project_end(Zone, EndingDST),
|
EndDatesP1={_,_,UD}= ezic_zone:project_end(Zone, EndingDST),
|
||||||
{WDm, SDm, UDm}= ezic_date:m1s(EndDatesP1),
|
{WDm, SDm, UDm}= ezic_date:m1s(EndDatesP1),
|
||||||
EndFlat= ?ENDFLAT(FlatStub, WDm, SDm, UDm, EndingDST),
|
EndFlat= ?ENDFLAT(FlatStub, WDm, SDm, UDm, EndingDST),
|
||||||
|
|
||||||
RetNextFlat= #flatzone{dstoffset=EndingDST, utc_from=UD},
|
RetNextFlat= #flatzone{dstoffset=EndingDST, utc_from=UD},
|
||||||
|
|
||||||
%% ?debugVal(EndFlat),
|
%% ?debugVal(EndFlat),
|
||||||
@@ -280,7 +280,7 @@ finish_and_start_flat(max_year, FlatStub, DSTOffset) ->
|
|||||||
Stop= {{?MAXYEAR+1,1,1},{0,0,0}},
|
Stop= {{?MAXYEAR+1,1,1},{0,0,0}},
|
||||||
NextFlat= #flatzone{utc_from=Stop},
|
NextFlat= #flatzone{utc_from=Stop},
|
||||||
{EndFlat, NextFlat}.
|
{EndFlat, NextFlat}.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% both timezone and rule are ending at the same time
|
%% both timezone and rule are ending at the same time
|
||||||
@@ -325,7 +325,7 @@ ms_guards(s, D) ->
|
|||||||
ms_guards2(D, '$3', '$4');
|
ms_guards2(D, '$3', '$4');
|
||||||
ms_guards(X, D) when X=:=w;X=:=undefined ->
|
ms_guards(X, D) when X=:=w;X=:=undefined ->
|
||||||
ms_guards2(D, '$1', '$2').
|
ms_guards2(D, '$1', '$2').
|
||||||
|
|
||||||
|
|
||||||
ms_guards2(D, From, To) ->
|
ms_guards2(D, From, To) ->
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ load() ->
|
|||||||
|
|
||||||
%% returns all records, parsed from the tzdata files in directory Dir.
|
%% returns all records, parsed from the tzdata files in directory Dir.
|
||||||
load(Dir) ->
|
load(Dir) ->
|
||||||
{ok, Records} =
|
{ok, Records} =
|
||||||
case filelib:is_dir(Dir) of
|
case filelib:is_dir(Dir) of
|
||||||
true -> {ok, parse_dir(Dir)};
|
true -> {ok, parse_dir(Dir)};
|
||||||
false -> erlang:error({not_a_directory, Dir})
|
false -> erlang:error({not_a_directory, Dir})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
Records.
|
Records.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ clean_line(Line) ->
|
|||||||
Line1= string:strip(Line),
|
Line1= string:strip(Line),
|
||||||
Line2= string:strip(Line1, both, $\n),
|
Line2= string:strip(Line1, both, $\n),
|
||||||
Line3= string:strip(Line2, both, $\t),
|
Line3= string:strip(Line2, both, $\t),
|
||||||
|
|
||||||
%% remove comments and returns
|
%% remove comments and returns
|
||||||
FinalLine=Line3,
|
FinalLine=Line3,
|
||||||
CPos= string:chr(FinalLine, $#),
|
CPos= string:chr(FinalLine, $#),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ year("max") -> maximum;
|
|||||||
year("only") -> only;
|
year("only") -> only;
|
||||||
year(X) ->
|
year(X) ->
|
||||||
list_to_integer(X).
|
list_to_integer(X).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
% X=last(Mon,Tue,Wed,...,Sun) -> {last, (Mon,Tue,Web,...,Sun)}
|
% 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()
|
% X=int()
|
||||||
day_pattern(X) ->
|
day_pattern(X) ->
|
||||||
list_to_integer(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) ->
|
tz_abbr(Format, Pos) ->
|
||||||
First=string:substr(Format, 1, Pos-1),
|
First=string:substr(Format, 1, Pos-1),
|
||||||
Last=string:substr(Format, Pos+2),
|
Last=string:substr(Format, Pos+2),
|
||||||
string:concat(First, [$~, $s|Last]).
|
string:concat(First, [$~, $s|Last]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ separate(Records) ->
|
|||||||
Leaps= [Z || Z=#leap{} <- Records],
|
Leaps= [Z || Z=#leap{} <- Records],
|
||||||
Links= [Z || Z=#link{} <- Records],
|
Links= [Z || Z=#link{} <- Records],
|
||||||
{ok, Zones, Rules, Leaps, Links}.
|
{ok, Zones, Rules, Leaps, Links}.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ parse([Name,FromS,ToS,_Type,InS,OnS,AtS,SaveS,Letters]) ->
|
|||||||
In= ezic_date:month_to_num(InS),
|
In= ezic_date:month_to_num(InS),
|
||||||
On= ezic_parse:day_pattern(OnS),
|
On= ezic_parse:day_pattern(OnS),
|
||||||
At= ezic_parse:time(AtS),
|
At= ezic_parse:time(AtS),
|
||||||
|
|
||||||
Save= ezic_parse:time_val(SaveS),
|
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},
|
in=In, on=On, at=At, save=Save, letters=Letters},
|
||||||
{ok, Rule}.
|
{ok, Rule}.
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ years_after(Y, {_From, To}) when Y > To ->
|
|||||||
years_after(Y, {From, To}) ->
|
years_after(Y, {From, To}) ->
|
||||||
{erlang:max(Y,From), To}.
|
{erlang:max(Y,From), To}.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% INTERNAL
|
% INTERNAL
|
||||||
@@ -76,7 +76,7 @@ project_next2(Rule, Offset, UTCAfter, DSTOffset, Years={FromYear, _}) ->
|
|||||||
RuleDate= ezic_date:for_rule_utc(Rule, Offset, DSTOffset, 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
|
case ezic_date:compare(UTCAfter, RuleDate) andalso (not ezic_date:equal(UTCAfter, RuleDate)) of
|
||||||
true -> {FromYear, RuleDate};
|
true -> {FromYear, RuleDate};
|
||||||
false ->
|
false ->
|
||||||
RestYears= years_after(FromYear+1, Years),
|
RestYears= years_after(FromYear+1, Years),
|
||||||
project_next2(Rule, Offset, UTCAfter, DSTOffset, RestYears)
|
project_next2(Rule, Offset, UTCAfter, DSTOffset, RestYears)
|
||||||
end.
|
end.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
%%% File : ezic_sup.erl
|
%%% File : ezic_sup.erl
|
||||||
%%% Author : aj <aj@fattie>
|
%%% Author : aj <aj@fattie>
|
||||||
%%% Description :
|
%%% Description :
|
||||||
%%%
|
%%%
|
||||||
%%% Created : 15 Nov 2010 by aj <aj@fattie>
|
%%% Created : 15 Nov 2010 by aj <aj@fattie>
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
@@ -34,9 +34,9 @@ start_link(StartArgs) ->
|
|||||||
%% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
|
%% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
|
||||||
%% ignore |
|
%% ignore |
|
||||||
%% {error, Reason}
|
%% {error, Reason}
|
||||||
%% Description: Whenever a supervisor is started using
|
%% Description: Whenever a supervisor is started using
|
||||||
%% supervisor:start_link/[2,3], this function is called by the new process
|
%% supervisor:start_link/[2,3], this function is called by the new process
|
||||||
%% to find out about restart strategy, maximum restart frequency and child
|
%% to find out about restart strategy, maximum restart frequency and child
|
||||||
%% specifications.
|
%% specifications.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
init(StartArgs) ->
|
init(StartArgs) ->
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ parse([Name,GmtOffS,Rule,FormatS | UntilTokens]) ->
|
|||||||
GmtOff= ezic_parse:time_val(GmtOffS),
|
GmtOff= ezic_parse:time_val(GmtOffS),
|
||||||
Until = ezic_parse:until(UntilTokens),
|
Until = ezic_parse:until(UntilTokens),
|
||||||
Format= ezic_parse:tz_abbr(FormatS),
|
Format= ezic_parse:tz_abbr(FormatS),
|
||||||
|
|
||||||
{ok, #zone{
|
{ok, #zone{
|
||||||
name=Name, gmtoff=GmtOff, rule=Rule,
|
name=Name, gmtoff=GmtOff, rule=Rule,
|
||||||
format=Format, until=Until
|
format=Format, until=Until
|
||||||
@@ -46,11 +46,11 @@ get_zone_utc(_, []) ->
|
|||||||
erlang:error(no_current);
|
erlang:error(no_current);
|
||||||
get_zone_utc(_UTCDatetime, _Zones) ->
|
get_zone_utc(_UTCDatetime, _Zones) ->
|
||||||
not_done.
|
not_done.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
% returns {[SimilarZone], [DifferentZone]}
|
|
||||||
|
% returns {[SimilarZone], [DifferentZone]}
|
||||||
% where Similar Zones are those with the same name as Zone
|
% where Similar Zones are those with the same name as Zone
|
||||||
% and DifferentZones are all the rest
|
% and DifferentZones are all the rest
|
||||||
split_by_name(#zone{name=N}, Zones) ->
|
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)
|
% returns ALL datetimes projected for zone end (given current DST Offset)
|
||||||
project_end(#zone{until=Until, gmtoff=Offset}, DSTOffset) ->
|
project_end(#zone{until=Until, gmtoff=Offset}, DSTOffset) ->
|
||||||
NUntil= ezic_date:normalize(Until),
|
NUntil= ezic_date:normalize(Until),
|
||||||
@@ -84,20 +83,20 @@ project_end_utc(Zone=#zone{}, DSTOffset) ->
|
|||||||
% ?debugVal(Zone),
|
% ?debugVal(Zone),
|
||||||
{_,_,UTCDatetime}= project_end(Zone, DSTOffset),
|
{_,_,UTCDatetime}= project_end(Zone, DSTOffset),
|
||||||
UTCDatetime.
|
UTCDatetime.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% returns [Zone | Rest] where Zone is the next zone after UTCFrom,
|
%% returns [Zone | Rest] where Zone is the next zone after UTCFrom,
|
||||||
%% subject to the DST offset.
|
%% subject to the DST offset.
|
||||||
%% Note that dst differences *can* change which zone comes next,
|
%% 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).
|
%% 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.
|
%% this method covers that event, anyhow. see unit tests for examples.
|
||||||
next(ZoneList, UTCFrom, DSTOff) ->
|
next(ZoneList, UTCFrom, DSTOff) ->
|
||||||
%% ?debugMsg("next:"),
|
%% ?debugMsg("next:"),
|
||||||
%% ?debugVal(ZoneList),
|
%% ?debugVal(ZoneList),
|
||||||
%% ?debugVal(UTCFrom),
|
%% ?debugVal(UTCFrom),
|
||||||
|
|
||||||
DatedList= lists:map(
|
DatedList= lists:map(
|
||||||
fun(Z=#zone{until=Until, gmtoff=Offset})->
|
fun(Z=#zone{until=Until, gmtoff=Offset})->
|
||||||
NUntil= ezic_date:normalize(Until),
|
NUntil= ezic_date:normalize(Until),
|
||||||
|
|||||||
@@ -5,30 +5,30 @@
|
|||||||
|
|
||||||
project_next_test_() ->
|
project_next_test_() ->
|
||||||
[
|
[
|
||||||
|
|
||||||
% simple UTC example
|
% simple UTC example
|
||||||
?_assertEqual({2010, {{2010,11,10},{16,20,0}}},
|
?_assertEqual({2010, {{2010,11,10},{16,20,0}}},
|
||||||
ezic_rule:project_next(
|
ezic_rule:project_next(
|
||||||
#rule{from=1984, to=2032, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
|
#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}}
|
, {-5,0,0}, {-1,0,0}, {{2010,11,10},{0,0,0}}
|
||||||
))
|
))
|
||||||
|
|
||||||
% skip a year UTC example
|
% 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(
|
ezic_rule:project_next(
|
||||||
#rule{from=1984, to=2032, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
|
#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}}
|
, {-5,0,0}, {-1,0,0}, {{2010,11,10},{16,21,0}}
|
||||||
))
|
))
|
||||||
|
|
||||||
% skip 3 years UTC example
|
% 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(
|
ezic_rule:project_next(
|
||||||
#rule{from=1984, to=2032, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
|
#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}}
|
, {-5,0,0}, {-1,0,0}, {{2012,11,11},{16,20,0}}
|
||||||
))
|
))
|
||||||
|
|
||||||
% no solution
|
% no solution
|
||||||
, ?_assertEqual(none,
|
, ?_assertEqual(none,
|
||||||
ezic_rule:project_next(
|
ezic_rule:project_next(
|
||||||
#rule{from=1984, to=2010, in=11, on=10, at=#tztime{time={16,20,0}, flag=u}}
|
#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}}
|
, {-5,0,0}, {-1,0,0}, {{2012,11,11},{16,20,0}}
|
||||||
|
|||||||
@@ -17,17 +17,17 @@ split_by_name_test_() ->
|
|||||||
|
|
||||||
project_end_utc_test_() ->
|
project_end_utc_test_() ->
|
||||||
[
|
[
|
||||||
?_assertEqual({{2010,11,10},{16,20,0}},
|
?_assertEqual({{2010,11,10},{16,20,0}},
|
||||||
ezic_zone:project_end_utc(
|
ezic_zone:project_end_utc(
|
||||||
#zone{until={{2010,11,10},#tztime{time={10,20,0}, flag=w}}, gmtoff={-7,0,0}}
|
#zone{until={{2010,11,10},#tztime{time={10,20,0}, flag=w}}, gmtoff={-7,0,0}}
|
||||||
, {1,0,0}))
|
, {1,0,0}))
|
||||||
|
|
||||||
, ?_assertEqual({{2010,11,10},{16,20,0}},
|
, ?_assertEqual({{2010,11,10},{16,20,0}},
|
||||||
ezic_zone:project_end_utc(
|
ezic_zone:project_end_utc(
|
||||||
#zone{until={{2010,11,10},#tztime{time={9,20,0}, flag=s}}, gmtoff={-7,0,0}}
|
#zone{until={{2010,11,10},#tztime{time={9,20,0}, flag=s}}, gmtoff={-7,0,0}}
|
||||||
, {1,0,0}))
|
, {1,0,0}))
|
||||||
|
|
||||||
, ?_assertEqual({{2010,11,10},{16,20,0}},
|
, ?_assertEqual({{2010,11,10},{16,20,0}},
|
||||||
ezic_zone:project_end_utc(
|
ezic_zone:project_end_utc(
|
||||||
#zone{until={{2010,11,10},#tztime{time={16,20,0}, flag=u}}, gmtoff={-7,0,0}}
|
#zone{until={{2010,11,10},#tztime{time={16,20,0}, flag=u}}, gmtoff={-7,0,0}}
|
||||||
, {1,0,0}))
|
, {1,0,0}))
|
||||||
@@ -46,11 +46,11 @@ next_datetime_test_() ->
|
|||||||
Z1=BZ#zone{until={{2010,11,15},#tztime{}}}
|
Z1=BZ#zone{until={{2010,11,15},#tztime{}}}
|
||||||
, Z2=BZ#zone{until={{2010,11,5},#tztime{}}}
|
, Z2=BZ#zone{until={{2010,11,5},#tztime{}}}
|
||||||
, Z3=BZ#zone{until={{2010,11,25},#tztime{}}}
|
, Z3=BZ#zone{until={{2010,11,25},#tztime{}}}
|
||||||
|
|
||||||
, Zt1=BZ#zone{until={{2010,11,5},#tztime{time={5,0,0}, flag=u}}}
|
, 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}}}
|
, 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}}}
|
, Zt3=BZ#zone{until={{2010,11,5},#tztime{time={17,0,0}, flag=u}}}
|
||||||
|
|
||||||
, Zy1=BZ#zone{until={{1978,11,5},#tztime{}}}
|
, Zy1=BZ#zone{until={{1978,11,5},#tztime{}}}
|
||||||
, Zy2=BZ#zone{until={{1979,11,5},#tztime{}}}
|
, Zy2=BZ#zone{until={{1979,11,5},#tztime{}}}
|
||||||
, Zy3=BZ#zone{until={{1980,11,5},#tztime{}}}
|
, Zy3=BZ#zone{until={{1980,11,5},#tztime{}}}
|
||||||
|
|||||||
Reference in New Issue
Block a user