Skip to content

Commit

Permalink
Add list_timezones/0, export adjust_datetime, accept strings in dst:c…
Browse files Browse the repository at this point in the history
…heck/2

Conflicts:

	src/localtime.erl
	src/localtime_dst.erl
  • Loading branch information
choptastic committed Mar 11, 2014
1 parent 9caa2b2 commit 6e14b6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/localtime.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%% vim: ts=4 sw=4 et
%% @author Dmitry S. Melnikov (dmitryme@gmail.com)
%% @copyright 2010 Dmitry S. Melnikov

-module(localtime).

-author("Dmitry Melnikov <dmitryme@gmail.com>").
Expand All @@ -17,6 +17,9 @@
,tz_name/2
,tz_shift/2
,tz_shift/3
,get_timezone/1
,list_timezones/0
,adjust_datetime/2
]).

% utc_to_local(UtcDateTime, Timezone) -> LocalDateTime | [LocalDateTime, DstLocalDateTime] | {error, ErrDescr}
Expand Down Expand Up @@ -185,14 +188,18 @@ tz_shift(LocalDateTime, TimezoneFrom, TimezoneTo) ->
Err
end.

% =======================================================================
% privates
% =======================================================================
list_timezones() ->
dict:fetch_keys(?tz_index).

adjust_datetime(DateTime, Minutes) ->
Seconds = calendar:datetime_to_gregorian_seconds(DateTime) + Minutes * 60,
calendar:gregorian_seconds_to_datetime(Seconds).

% =======================================================================
% privates
% =======================================================================


invert_shift(Minutes) ->
-Minutes.

Expand Down
14 changes: 13 additions & 1 deletion src/localtime_dst.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
%% vim: ts=4 sw=4 et
%% @author Dmitry S. Melnikov (dmitryme@gmail.com)
%% @copyright 2010 Dmitry S. Melnikov

-module(localtime_dst).

-author("Dmitry Melnikov <dmitryme@gmail.com>").

-include("tz_database.hrl").
-include("tz_index.hrl").

-export(
[
check/2
Expand All @@ -15,7 +19,15 @@

% check(DateTime, TimeZone) -> is_in_dst | is_not_in_dst | ambiguous_time | time_not_exists
% DateTime = DateTime()
% TimeZone = tuple()
% TimeZone = tuple() | string()
check(DateTime, Timezone) when is_list(Timezone) ->
case lists:keyfind(localtime:get_timezone(Timezone), 1, ?tz_database) of
false ->
{error, unknown_tz};
TZ ->
check(DateTime, TZ)
end;

check({Date = {Year, _, _},Time}, {_, _, _, _Shift, DstShift, DstStartRule, DstStartTime, DstEndRule, DstEndTime}) ->
DstStartDay = get_dst_day_of_year(DstStartRule, Year),
DstEndDay = get_dst_day_of_year(DstEndRule, Year),
Expand Down

0 comments on commit 6e14b6e

Please sign in to comment.