Permalink
Browse files

Support no-argument version of "date" filter

  • Loading branch information...
1 parent f40805a commit 8a89e64c99557ad89e12f1863e7499a3734e80cc @evanmiller evanmiller committed Mar 21, 2011
Showing with 9 additions and 2 deletions.
  1. +5 −2 src/erlydtl_filters.erl
  2. +4 −0 tests/src/erlydtl_unittests.erl
@@ -51,6 +51,7 @@
capfirst/1,
center/2,
cut/2,
+ date/1,
date/2,
default/2,
default_if_none/2,
@@ -186,11 +187,13 @@ cut(Input, Arg) when is_binary(Input) ->
cut(Input, [Char]) when is_list(Input) ->
cut(Input, Char, []).
+%% @doc Formats a date according to the default format.
+date(Input) ->
+ date(Input, "F j, Y").
+
%% @doc Formats a date according to the given format.
date(Input, FormatStr) when is_binary(Input) ->
list_to_binary(date(binary_to_list(Input), FormatStr));
-date(Input, "") ->
- date(Input, "F j, Y");
date({{_,_,_} = Date,{_,_,_} = Time}, FormatStr) ->
erlydtl_dateformat:format({Date, Time}, FormatStr);
date({_,_,_} = Date, FormatStr) ->
@@ -360,6 +360,10 @@ tests() ->
<<"{{ var1|date:\"jS F Y H:i\" }}">>,
[{var1, {{1975,7,24}, {7,13,1}}}],
<<"24th July 1975 07:13">>},
+ {"|date 3",
+ <<"{{ var1|date }}">>,
+ [{var1, {{1975,7,24}, {7,13,1}}}],
+ <<"July 24, 1975">>},
{"|default:\"foo\" 1",
<<"{{ var1|default:\"foo\" }}">>, [], <<"foo">>},
{"|default:\"foo\" 2",

0 comments on commit 8a89e64

Please sign in to comment.