Skip to content

Loading…

Fix pgsql timestamp #36

Merged
merged 5 commits into from

2 participants

@runejuhl

PostgreSQL defaults to returning timestamps as YYYY-MM-DD HH:mm:SS.ssssss, which breaks existing ErlyDTL functionality. This patch adds the functionality, and adds a test.

I was a bit unsure if this should go here or if it should be handled in boss_db, but after consulting with @talklittle (thanks!) in the #chicagoboss IRC channel, we agreed it should be in ErlyDTL

@evanmiller

Sounds good, thanks

@evanmiller evanmiller merged commit a25e0ca into erlydtl:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 27 additions and 1 deletion.
  1. +3 −1 src/filter_lib/erlydtl_dateformat.erl
  2. +24 −0 tests/src/erlydtl_dateformat_tests.erl
View
4 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 ->
View
24 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"}] },
Something went wrong with that request. Please try again.