fixed bug with rule choice; dst was not being calculated correctly, Thanks Adelaide!

This commit is contained in:
aj
2010-11-04 04:28:23 -07:00
parent 7dd76519a0
commit f4a48f09cf
2 changed files with 11 additions and 10 deletions

View File

@@ -11,27 +11,27 @@
localtime(TzName) -> localtime(TzName) ->
Now= erlang:universaltime(), time(erlang:universaltime(), TzName).
time(Datetime, TzName) ->
Zones= ezic_db:zones(TzName), Zones= ezic_db:zones(TzName),
% ?debug("All Zones: ~p", [Zones]), % ?debug("All Zones: ~p", [Zones]),
CZone= ezic_zone:current(Now, Zones), CZone= ezic_zone:current(Datetime, Zones),
% ?debug("Current Zone: ~p", [CZone]), % ?debug("Current Zone: ~p", [CZone]),
RuleName= CZone#zone.rule, RuleName= CZone#zone.rule,
Rules= ezic_db:rules(RuleName), Rules= ezic_db:rules(RuleName),
% ?debug("All Rules: ~p", [Rules]), % ?debug("All Rules: ~p", [Rules]),
CRule= ezic_rule:current(Now, Rules), CRule= ezic_rule:current(Datetime, Rules),
% ?debug("Current Rule: ~p", [CRule]), % ?debug("Current Rule: ~p", [CRule]),
OffsetSec= ezic_zone:offset_sec(CZone), OffsetSec= ezic_zone:offset_sec(CZone),
DSTSec= ezic_rule:dst_sec(CRule), DSTSec= ezic_rule:dst_sec(CRule),
%
SecDiff= OffsetSec + DSTSec, SecDiff= OffsetSec + DSTSec,
?gs2dt(?dt2gs(Now) + SecDiff). ?gs2dt(?dt2gs(Datetime) + SecDiff).
@@ -56,4 +56,4 @@ test() ->
fun(TZ)-> fun(TZ)->
io:format("~s: ~p~n", [TZ, localtime(TZ)]) io:format("~s: ~p~n", [TZ, localtime(TZ)])
end, end,
["Asia/Tokyo", "America/New_York", "America/Los_Angeles", "America/Jamaica"]). ["Asia/Tokyo", "America/New_York", "America/Los_Angeles", "America/Jamaica", "Australia/Adelaide"]).

View File

@@ -19,10 +19,11 @@ current(Now, Rules) ->
% newest first
sort(R1, R2) -> sort(R1, R2) ->
T1= from_time(R1), T1= from_time(R1),
T2= from_time(R2), T2= from_time(R2),
ezic_date:compare_datetimes(T1, T2). ezic_date:compare_datetimes(T2, T1).