Skip to content

Commit

Permalink
handle 'none' translation function separately
Browse files Browse the repository at this point in the history
  • Loading branch information
oxpa committed Sep 18, 2015
1 parent 1a99256 commit cba06ff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/filter_lib/erlydtl_dateformat.erl
Expand Up @@ -70,19 +70,27 @@ format(DateTime, FormatString) ->
FormatString.

%% The same set of functions with TranslationFunction and Locale args
%% Translation function may be 'none' atom - handle this separately
%% replacing atom with a stub function (it's easier to do it this way)
format(FormatString, TransFun, Locale) when is_binary(FormatString) ->
format(binary_to_list(FormatString), TransFun, Locale);
format(FormatString, none, Locale) ->
format(FormatString, fun stub_tran/2, <<>>);
format(FormatString, TransFun, Locale) ->
{Date, Time} = erlang:localtime(),
replace_tags(Date, Time, FormatString, TransFun, Locale).

format(DateTime, FormatString, TransFun, Locale) when is_binary(FormatString) ->
format(DateTime, binary_to_list(FormatString), TransFun, Locale);
format(DateTime, FormatString, none, Locale) ->
format(DateTime, FormatString, fun stub_tran/2, <<>>);
format({{_,_,_} = Date,{_,_,_} = Time}, FormatString, TransFun, Locale) ->
replace_tags(Date, Time, FormatString, TransFun, Locale );

format({_,_,_} = Date, FormatString, none, Locale) ->
replace_tags(Date, {0,0,0}, FormatString, fun stub_tran/2, <<>>);
format({_,_,_} = Date, FormatString, TransFun, Locale) ->
replace_tags(Date, {0,0,0}, FormatString, TransFun, Locale );
replace_tags(Date, {0,0,0}, FormatString, TransFun, Locale);
format(DateTime, FormatString, _TransFun, _Locale) ->
io:format("Unrecognised date paramater : ~p~n", [DateTime]),
FormatString.
Expand Down

0 comments on commit cba06ff

Please sign in to comment.