implements a fix for losing the ets dbs on a bad lookup
The `ezic_db` server would crash on a bad lookup (no_zone, ambiguous_zone, etc.). The old error notification method for bad lookups (crashing) was killing the server and apparently eliminating the in-memory tables.
This commit is contained in:
16
src/ezic.erl
16
src/ezic.erl
@@ -32,13 +32,8 @@ localtime(TzName) ->
|
||||
|
||||
utc_to_local(UTCDatetime, TzName) ->
|
||||
NormalDatetime= ezic_date:normalize(UTCDatetime, u),
|
||||
#flatzone{offset=Offset, dstoffset=DSTOffset}= ezic_db:flatzone(NormalDatetime, TzName),
|
||||
utc_to_local_handleFlatzone(UTCDatetime, ezic_db:flatzone(NormalDatetime, TzName)).
|
||||
|
||||
ezic_date:add_offset(
|
||||
ezic_date:add_offset(
|
||||
UTCDatetime
|
||||
, Offset)
|
||||
, DSTOffset).
|
||||
|
||||
|
||||
local_to_utc(LocalDatetime, TzName) ->
|
||||
@@ -101,3 +96,12 @@ test() ->
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% PRIVATE
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
utc_to_local_handleFlatzone(_, X={error,_}) ->
|
||||
X;
|
||||
utc_to_local_handleFlatzone(UTCDatetime, #flatzone{offset=Offset, dstoffset=DSTOffset}) ->
|
||||
ezic_date:add_offset(
|
||||
ezic_date:add_offset(
|
||||
UTCDatetime
|
||||
, Offset)
|
||||
, DSTOffset).
|
||||
|
||||
@@ -34,11 +34,11 @@ flatzone(Date, TzName) ->
|
||||
1 ->
|
||||
hd(FlatZones);
|
||||
2 ->
|
||||
erlang:error(ambiguous_zone, FlatZones);
|
||||
{error, {ambiguous_zone, FlatZones}};
|
||||
0 ->
|
||||
erlang:error(no_zone);
|
||||
{error, no_zone};
|
||||
_ ->
|
||||
erlang:error(should_not_happen, {FlatZones, Date, TzName})
|
||||
{error, {should_not_happen, {FlatZones, Date, TzName}}}
|
||||
end.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user