Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

date 'h' format fix #30

Merged
merged 1 commit into from

2 participants

@bluegraybox

Hi,

Just a quick fix for date 'h' formatting (12-hour, leading zero). It was trying to do integer_to_list twice. Threw in some extra unit tests while I was at it.

I came to this by way of ChicagoBoss. New to it, but loving it!

Thanks,
Colin

Colin MacDonald 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.
2b29a5f
@evanmiller
Owner

"Extra unit tests" are music to my ears. Thanks for the patch!

@evanmiller evanmiller merged commit 9aa03d7 into erlydtl:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 8, 2012
  1. Fixed date formatting for 'h', added tests.

    Colin MacDonald authored
    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.
This page is out of date. Refresh to see the latest.
View
2  src/filter_lib/erlydtl_dateformat.erl
@@ -132,7 +132,7 @@ tag_to_value($G, _, {H,_,_}) ->
% Hour, 12-hour format; i.e. '01' to '12'
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'
tag_to_value($H, _, {H,_,_}) ->
View
12 tests/src/erlydtl_dateformat_tests.erl
@@ -11,11 +11,12 @@ run_tests() ->
[{"a", "a.m."}, {"A", "AM"}, {"c", "1979-07-08T00:00:00"},
{"d", "08"}, {"D", "Sun"}, {"f", "12"}, {"F", "July"},
{"g", "12"}, {"G", "0"},
+ {"h", "12"}, {"H", "00"}, {"i", "00"},
{"j", "8"}, {"l", "Sunday"}, {"L", "False"},
{"m", "07"}, {"M", "Jul"}, {"b", "jul"},
{"n", "7"}, {"N", "July"}, {"P", "midnight"},
{"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 o\\f F", "8th of July"},
% We expect these to come back verbatim
@@ -35,11 +36,12 @@ run_tests() ->
[{"a", "p.m."}, {"A", "PM"}, {"c", "1979-07-08T22:07:12"},
{"d", "08"}, {"D", "Sun"}, {"f", "10:07"}, {"F", "July"},
{"g", "10"}, {"G", "22"},
+ {"h", "10"}, {"H", "22"}, {"i", "07"},
{"j", "8"}, {"l", "Sunday"}, {"L", "False"},
{"m", "07"}, {"M", "Jul"}, {"b", "jul"},
{"n", "7"}, {"N", "July"}, {"P", "10:07 p.m."},
{"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 o\\f F", "8th of July"},
% We expect these to come back verbatim
@@ -58,11 +60,12 @@ run_tests() ->
[{"a", "a.m."}, {"A", "AM"}, {"c", "2008-12-25T07:00:09"},
{"d", "25"}, {"D", "Thu"}, {"f", "7"}, {"F", "December"},
{"g", "7"}, {"G", "7"},
+ {"h", "07"}, {"H", "07"}, {"i", "00"},
{"j", "25"}, {"l", "Thursday"}, {"L", "True"},
{"m", "12"}, {"M", "Dec"}, {"b", "dec"},
{"n", "12"}, {"N", "Dec."}, {"P", "7 a.m."},
{"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 o\\f F", "25th of December"},
% We expect these to come back verbatim
@@ -81,11 +84,12 @@ run_tests() ->
[{"a", "p.m."}, {"A", "PM"}, {"c", "2004-02-29T12:00:59"},
{"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", "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 o\\f F", "29th of February"},
% We expect these to come back verbatim
Something went wrong with that request. Please try again.