Browse Source

Merge pull request #36 from runejuhl/fix-pgsql-timestamp

Fix pgsql timestamp
Evan Miller 13 years ago
parent
commit
a25e0ca042
2 changed files with 27 additions and 1 deletions
  1. 3 1
      src/filter_lib/erlydtl_dateformat.erl
  2. 24 0
      tests/src/erlydtl_dateformat_tests.erl

+ 3 - 1
src/filter_lib/erlydtl_dateformat.erl

@@ -359,9 +359,11 @@ monthname(12) -> "december";
 monthname(_) -> "???".
 
 % Utility functions
+integer_to_list_zerofill(N) when not is_integer(N) ->
+    integer_to_list_zerofill(erlang:round(N));
 integer_to_list_zerofill(N) when N < 10 ->
     lists:flatten(io_lib:format("~2..0B", [N]));
-integer_to_list_zerofill(N) ->
+integer_to_list_zerofill(N) when is_integer(N) ->
     integer_to_list(N).
 
 ucfirst([First | Rest]) when First >= $a, First =< $z ->

+ 24 - 0
tests/src/erlydtl_dateformat_tests.erl

@@ -102,6 +102,30 @@ run_tests() ->
           %{"Z", "3600"}
          ]
       },
+      {
+         "datetime 4",
+         {{2004, 2, 29}, {12, 0, 09.256687}}, % date/time tuple
+         [{"a", "p.m."}, {"A", "PM"}, {"c", "2004-02-29T12:00:09"},
+          {"d", "29"}, {"D", "Sun"}, {"f", "12"}, {"F", "February"},
+          {"g", "12"}, {"G", "12"},
+          {"h", "12"}, {"H", "12"}, {"i", "00"},
+          {"j", "29"}, {"l", "Sunday"}, {"L", "True"},
+          {"m", "02"}, {"M", "Feb"}, {"b", "feb"},
+          {"n", "2"}, {"N", "Feb."}, {"P", "noon"},
+          {"s", "09"}, {"S", "th"}, {"t", "29"},
+          {"w", "0"}, {"W", "9"}, {"y", "04"}, {"Y", "2004"}, {"z", "58"},
+          {"jS F Y H:i", "29th February 2004 12:00"},
+          {"jS o\\f F", "29th of February"},
+          % We expect these to come back verbatim
+          {"x", "x"}, {"C", "C"}, {";", ";"}, {"%", "%"}
+          % TODO : timzeone related tests.
+          %{"r", "Sun, 29 Feb 2004 12:00:59 +0000"},
+          %{"O", "0000"},
+          %{"T", "CET"},
+          %{"U", "300531600"},
+          %{"Z", "3600"}
+         ]
+      },
       % Weeknum tests.  Largely based on examples from :
       %   http://en.wikipedia.org/wiki/ISO_week_date
       { "weeknum 1.1",  {2005,  1,  1}, [{"W", "53"}] },