ezic:local_to_utc/2 added, working.
in the case of ambiguous timezones, an "ambiguous_zone" error is thrown with the two valid zones. if no zones existed for the given local time (i.e. DST eliminated the hour in question), a "no_zone" error is thrown. otherwise, the date is returned
This commit is contained in:
11
src/ezic.erl
11
src/ezic.erl
@@ -4,6 +4,7 @@
|
|||||||
-export([
|
-export([
|
||||||
localtime/1
|
localtime/1
|
||||||
, utc_to_local/2
|
, utc_to_local/2
|
||||||
|
, local_to_utc/2
|
||||||
, next_timechange/1
|
, next_timechange/1
|
||||||
, next_timechange_after/2
|
, next_timechange_after/2
|
||||||
]).
|
]).
|
||||||
@@ -44,6 +45,16 @@ utc_to_local(UTCDatetime, TzName) ->
|
|||||||
, DSTOffset).
|
, DSTOffset).
|
||||||
|
|
||||||
|
|
||||||
|
local_to_utc(LocalDatetime, TzName) ->
|
||||||
|
NormalDatetime= ezic_date:normalize(LocalDatetime, w),
|
||||||
|
#flatzone{offset=Offset, dstoffset=DSTOffset}= ezic_db:flatzone(NormalDatetime, TzName),
|
||||||
|
|
||||||
|
ezic_date:add_offset(
|
||||||
|
ezic_date:add_offset(
|
||||||
|
LocalDatetime
|
||||||
|
, Offset, {0,0,0})
|
||||||
|
, DSTOffset, {0,0,0}).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
next_timechange(TzName) ->
|
next_timechange(TzName) ->
|
||||||
|
|||||||
@@ -68,9 +68,18 @@ flatzone(Date, TzName) ->
|
|||||||
, ezic_flatten:contains_date(Fz, Date)]),
|
, ezic_flatten:contains_date(Fz, Date)]),
|
||||||
qlc:e(Q)
|
qlc:e(Q)
|
||||||
end,
|
end,
|
||||||
{atomic, [FlatZone]}= mnesia:transaction(F),
|
{atomic, FlatZones}= mnesia:transaction(F),
|
||||||
FlatZone.
|
|
||||||
|
|
||||||
|
case length(FlatZones) of
|
||||||
|
1 ->
|
||||||
|
hd(FlatZones);
|
||||||
|
2 ->
|
||||||
|
erlang:error(ambiguous_zone, FlatZones);
|
||||||
|
0 ->
|
||||||
|
erlang:error(no_zone);
|
||||||
|
_ ->
|
||||||
|
erlang:error(should_not_happen, {FlatZones, Date, TzName})
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|||||||
Reference in New Issue
Block a user