Browse Source

Fixed date formatting for 'h', added tests.

Removed extra integer_to_list conversion from tag_to_value/3 for $h.
Added tests for "h", "H", "i", and "Y" to each test case.
Colin MacDonald 13 years ago
parent
commit
2b29a5fb9a
2 changed files with 9 additions and 5 deletions
  1. 1 1
      src/filter_lib/erlydtl_dateformat.erl
  2. 8 4
      tests/src/erlydtl_dateformat_tests.erl

+ 1 - 1
src/filter_lib/erlydtl_dateformat.erl

@@ -132,7 +132,7 @@ tag_to_value($G, _, {H,_,_}) ->
 
 
 % Hour, 12-hour format; i.e. '01' to '12'
 % Hour, 12-hour format; i.e. '01' to '12'
 tag_to_value($h, _, {H,_,_}) ->
 tag_to_value($h, _, {H,_,_}) ->
-   integer_to_list_zerofill(integer_to_list(hour_24to12(H)));
+   integer_to_list_zerofill(hour_24to12(H));
 
 
 % Hour, 24-hour format; i.e. '00' to '23'
 % Hour, 24-hour format; i.e. '00' to '23'
 tag_to_value($H, _, {H,_,_}) ->
 tag_to_value($H, _, {H,_,_}) ->

+ 8 - 4
tests/src/erlydtl_dateformat_tests.erl

@@ -11,11 +11,12 @@ run_tests() ->
          [{"a", "a.m."}, {"A", "AM"}, {"c", "1979-07-08T00:00:00"},
          [{"a", "a.m."}, {"A", "AM"}, {"c", "1979-07-08T00:00:00"},
           {"d", "08"}, {"D", "Sun"}, {"f", "12"}, {"F", "July"},
           {"d", "08"}, {"D", "Sun"}, {"f", "12"}, {"F", "July"},
           {"g", "12"}, {"G", "0"},
           {"g", "12"}, {"G", "0"},
+          {"h", "12"}, {"H", "00"}, {"i", "00"},
           {"j", "8"}, {"l", "Sunday"}, {"L", "False"},
           {"j", "8"}, {"l", "Sunday"}, {"L", "False"},
           {"m", "07"}, {"M", "Jul"}, {"b", "jul"},
           {"m", "07"}, {"M", "Jul"}, {"b", "jul"},
           {"n", "7"}, {"N", "July"}, {"P", "midnight"},
           {"n", "7"}, {"N", "July"}, {"P", "midnight"},
           {"s", "00"}, {"S", "th"}, {"t", "31"},
           {"s", "00"}, {"S", "th"}, {"t", "31"},
-          {"w", "0"}, {"W", "27"}, {"y", "79"}, {"z", "189"},
+          {"w", "0"}, {"W", "27"}, {"y", "79"}, {"Y", "1979"}, {"z", "189"},
           {"jS F Y H:i", "8th July 1979 00:00"},
           {"jS F Y H:i", "8th July 1979 00:00"},
           {"jS o\\f F", "8th of July"},
           {"jS o\\f F", "8th of July"},
           % We expect these to come back verbatim
           % We expect these to come back verbatim
@@ -35,11 +36,12 @@ run_tests() ->
          [{"a", "p.m."}, {"A", "PM"}, {"c", "1979-07-08T22:07:12"},
          [{"a", "p.m."}, {"A", "PM"}, {"c", "1979-07-08T22:07:12"},
           {"d", "08"}, {"D", "Sun"}, {"f", "10:07"}, {"F", "July"},
           {"d", "08"}, {"D", "Sun"}, {"f", "10:07"}, {"F", "July"},
           {"g", "10"}, {"G", "22"},
           {"g", "10"}, {"G", "22"},
+          {"h", "10"}, {"H", "22"}, {"i", "07"},
           {"j", "8"}, {"l", "Sunday"}, {"L", "False"},
           {"j", "8"}, {"l", "Sunday"}, {"L", "False"},
           {"m", "07"}, {"M", "Jul"}, {"b", "jul"},
           {"m", "07"}, {"M", "Jul"}, {"b", "jul"},
           {"n", "7"}, {"N", "July"}, {"P", "10:07 p.m."},
           {"n", "7"}, {"N", "July"}, {"P", "10:07 p.m."},
           {"s", "12"}, {"S", "th"}, {"t", "31"},
           {"s", "12"}, {"S", "th"}, {"t", "31"},
-          {"w", "0"}, {"W", "27"}, {"y", "79"}, {"z", "189"},
+          {"w", "0"}, {"W", "27"}, {"y", "79"}, {"Y", "1979"}, {"z", "189"},
           {"jS F Y H:i", "8th July 1979 22:07"},
           {"jS F Y H:i", "8th July 1979 22:07"},
           {"jS o\\f F", "8th of July"},
           {"jS o\\f F", "8th of July"},
           % We expect these to come back verbatim
           % We expect these to come back verbatim
@@ -58,11 +60,12 @@ run_tests() ->
          [{"a", "a.m."}, {"A", "AM"}, {"c", "2008-12-25T07:00:09"},
          [{"a", "a.m."}, {"A", "AM"}, {"c", "2008-12-25T07:00:09"},
           {"d", "25"}, {"D", "Thu"}, {"f", "7"}, {"F", "December"},
           {"d", "25"}, {"D", "Thu"}, {"f", "7"}, {"F", "December"},
           {"g", "7"}, {"G", "7"},
           {"g", "7"}, {"G", "7"},
+          {"h", "07"}, {"H", "07"}, {"i", "00"},
           {"j", "25"}, {"l", "Thursday"}, {"L", "True"},
           {"j", "25"}, {"l", "Thursday"}, {"L", "True"},
           {"m", "12"}, {"M", "Dec"}, {"b", "dec"},
           {"m", "12"}, {"M", "Dec"}, {"b", "dec"},
           {"n", "12"}, {"N", "Dec."}, {"P", "7 a.m."},
           {"n", "12"}, {"N", "Dec."}, {"P", "7 a.m."},
           {"s", "09"}, {"S", "th"}, {"t", "31"},
           {"s", "09"}, {"S", "th"}, {"t", "31"},
-          {"w", "4"}, {"W", "52"}, {"y", "08"}, {"z", "360"},
+          {"w", "4"}, {"W", "52"}, {"y", "08"}, {"Y", "2008"}, {"z", "360"},
           {"jS F Y H:i", "25th December 2008 07:00"},
           {"jS F Y H:i", "25th December 2008 07:00"},
           {"jS o\\f F", "25th of December"},
           {"jS o\\f F", "25th of December"},
           % We expect these to come back verbatim
           % We expect these to come back verbatim
@@ -81,11 +84,12 @@ run_tests() ->
          [{"a", "p.m."}, {"A", "PM"}, {"c", "2004-02-29T12:00:59"},
          [{"a", "p.m."}, {"A", "PM"}, {"c", "2004-02-29T12:00:59"},
           {"d", "29"}, {"D", "Sun"}, {"f", "12"}, {"F", "February"},
           {"d", "29"}, {"D", "Sun"}, {"f", "12"}, {"F", "February"},
           {"g", "12"}, {"G", "12"},
           {"g", "12"}, {"G", "12"},
+          {"h", "12"}, {"H", "12"}, {"i", "00"},
           {"j", "29"}, {"l", "Sunday"}, {"L", "True"},
           {"j", "29"}, {"l", "Sunday"}, {"L", "True"},
           {"m", "02"}, {"M", "Feb"}, {"b", "feb"},
           {"m", "02"}, {"M", "Feb"}, {"b", "feb"},
           {"n", "2"}, {"N", "Feb."}, {"P", "noon"},
           {"n", "2"}, {"N", "Feb."}, {"P", "noon"},
           {"s", "59"}, {"S", "th"}, {"t", "29"},
           {"s", "59"}, {"S", "th"}, {"t", "29"},
-          {"w", "0"}, {"W", "9"}, {"y", "04"}, {"z", "58"},
+          {"w", "0"}, {"W", "9"}, {"y", "04"}, {"Y", "2004"}, {"z", "58"},
           {"jS F Y H:i", "29th February 2004 12:00"},
           {"jS F Y H:i", "29th February 2004 12:00"},
           {"jS o\\f F", "29th of February"},
           {"jS o\\f F", "29th of February"},
           % We expect these to come back verbatim
           % We expect these to come back verbatim