From 38de0fb581c0441b733786f4badfaae5832a04c2 Mon Sep 17 00:00:00 2001 From: Jack Tang Date: Mon, 11 Jan 2016 10:50:37 +0800 Subject: [PATCH] get_timezone supports binary input --- src/localtime.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/localtime.erl b/src/localtime.erl index c3eee0c..6a79da1 100644 --- a/src/localtime.erl +++ b/src/localtime.erl @@ -224,14 +224,18 @@ tr_char([H|T], From, To, Acc) -> end. -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, $_), case dict:find(TimeZoneNoSpaces, ?tz_index) of error -> TimeZoneNoSpaces; {ok, [TZName | _]} -> TZName - end. + end; +get_timezone(_) -> + throw({error, "Timezone should be string/binary"}). -ifdef(TEST). -include_lib("eunit/include/eunit.hrl").