Permalink
Browse files

handled case where zone and rule both end. dealing with Tripoli recur…

…sion bug (ambiguous year in ezic_date:for_rule)
  • Loading branch information...
drfloob committed Nov 13, 2010
1 parent a7b0adc commit 3f438e66e0168c6b3f17fe82b379c7626054fccf
Showing with 185 additions and 108 deletions.
  1. +2 −1 .gitignore
  2. +9 −6 Makefile
  3. +3 −1 src/ezic.erl
  4. +21 −15 src/ezic_date.erl
  5. +100 −52 src/ezic_flatten.erl
  6. +40 −32 src/ezic_rule.erl
  7. +10 −0 test/ezic_date_tests.erl
  8. +0 −1 test/test.erl
View
@@ -5,4 +5,5 @@ tmp/
commit_msg
tzdata/
\#*
-db/
+db/
+out
View
@@ -1,16 +1,19 @@
ERLC_WARNINGS := -W1
MNESIA_DIR := db
RUN_INIT := -run ezic_db init
-DEBUG := +debug_info -Ddebug
+DEBUG := -DNODEBUG
TEST :=
TZSET := northamerica
SHELL := /bin/bash
+
all : clean compile
+
nowarn : ERLC_WARNINGS = -W0
nowarn : clean compile
+
test : ERLC_WARNINGS := -W0
test : TEST := -DTEST
test : all
@@ -29,11 +32,8 @@ clean :
run :
erl -pa ebin -mnesia dir $(MNESIA_DIR) $(RUN_INIT)
-build : DEBUG =
-build : all
-
-devstart : RUN_INIT := $(RUN_INIT) -s ezic dev_start
+devstart : RUN_INIT := $(RUN_INIT) -s ezic dev_start -s erlang halt
devstart : all run
@@ -43,4 +43,7 @@ tzdata :
diff :
-git diff > /tmp/ezic.tmp.diff
- emacs /tmp/ezic.tmp.diff
+ emacs /tmp/ezic.tmp.diff
+
+
+debug : DEBUG := +debug_info -dNODEBUG
View
@@ -50,7 +50,9 @@ load(Folder) ->
dev_start() ->
% ezic:load(filename:join("priv","tzdata")),
- ezic_flatten:flatten().
+% ezic_flatten:flatten().
+ TZones= ezic_db:zones("Africa/Tripoli"),
+ ezic_flatten:flatten_all_zones(TZones).
test() ->
View
@@ -51,13 +51,15 @@ normalize(Date={Y,M,D})
when is_integer(Y), is_integer(M), is_integer(D) ->
{Date, #tztime{}};
normalize(R={{_,_,_}, #tztime{}}) ->
- R.
+ R;
+normalize({D={_,_,_}, T={_,_,_}}) ->
+ {D, #tztime{time=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(DT={D={_,_,_},T={HH,_,_}}, Flag)
+normalize({D={_,_,_},T={HH,_,_}}, Flag)
when is_atom(Flag), is_integer(HH) ->
DTz= {D, #tztime{time=T, flag=Flag}},
@@ -90,6 +92,7 @@ for_rule_relative(#rule{in=M, on=#tzon{day=Day, filter=Filter}, at=At}, Y) ->
%% returns set of ALL datetimes for a rule, given the gmt offset and
%% current dst offset.
+%% @bug @todo Year is ambiguous. In the case of Africa/Tripoli, a jan 1st, 1952 rule shows up as 1951 due to offset and dst.
for_rule(Rule, Offset, PrevDSTOffset, NextDSTOffset, Year) ->
{WT,ST,UT}= for_rule_old_dst(Rule, Offset, PrevDSTOffset, Year),
WTNew= add_offset(WT, PrevDSTOffset, NextDSTOffset),
@@ -101,7 +104,7 @@ for_rule(Rule, Offset, PrevDSTOffset, NextDSTOffset, Year) ->
for_rule_old_dst(Rule, Offset, PrevDSTOffset, Year) ->
DT= for_rule_relative(Rule, Year),
- {WT,ST,UT}= all_times(DT, Offset, PrevDSTOffset).
+ all_times(DT, Offset, PrevDSTOffset).
@@ -239,22 +242,25 @@ when is_integer(Y1), is_integer(Y2)
, is_integer(SS1), is_integer(SS2)
->
- DT1 =< DT2.
+ DT1 =< DT2;
+compare({Date1, #tztime{time=Time1, flag=F}}
+ , {Date2, #tztime{time=Time2, flag=F}}) ->
+
+ Date1 =< Date2 orelse Time1 =< time2;
+
+compare(X,Y) ->
+ XN= normalize(X),
+ YN= normalize(Y),
+ compare(XN, YN).
+
-% returns true if DT1 =:= DT2. False otherwise
-% both times are assumed to be in the same zone/DST context
-equal(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)
- ->
- DT1 =:= DT2.
+equal(X,Y) when X=:=Y ->
+ true;
+equal(_,_) ->
+ false.
Oops, something went wrong.

0 comments on commit 3f438e6

Please sign in to comment.