get_timezone supports binary input
This commit is contained in:
parent
1cb0303385
commit
38de0fb581
1 changed files with 6 additions and 2 deletions
|
@ -224,14 +224,18 @@ tr_char([H|T], From, To, Acc) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-define(SPACE_CHAR, 32).
|
-define(SPACE_CHAR, 32).
|
||||||
get_timezone(TimeZone) ->
|
get_timezone(TimeZone) when is_binary(TimeZone) ->
|
||||||
|
get_timezone(erlang:binary_to_list(TimeZone));
|
||||||
|
get_timezone(TimeZone) when is_list(TimeZone) ->
|
||||||
TimeZoneNoSpaces = tr_char(TimeZone, ?SPACE_CHAR, $_),
|
TimeZoneNoSpaces = tr_char(TimeZone, ?SPACE_CHAR, $_),
|
||||||
case dict:find(TimeZoneNoSpaces, ?tz_index) of
|
case dict:find(TimeZoneNoSpaces, ?tz_index) of
|
||||||
error ->
|
error ->
|
||||||
TimeZoneNoSpaces;
|
TimeZoneNoSpaces;
|
||||||
{ok, [TZName | _]} ->
|
{ok, [TZName | _]} ->
|
||||||
TZName
|
TZName
|
||||||
end.
|
end;
|
||||||
|
get_timezone(_) ->
|
||||||
|
throw({error, "Timezone should be string/binary"}).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue