Added tests to verify that {{ 'now' | date :'%Y' }} and {{ 'today' | date :'%Y' }} work.

In the case of Ruby 1.9.3, 'now' is no longer parsed.  For safe
measures, I've added 'today' as well.
This commit is contained in:
Jeremy Friesen
2012-04-19 10:48:55 -04:00
parent b8d7b9aeda
commit 5d0004a87e
2 changed files with 12 additions and 1 deletions

View File

@@ -169,7 +169,16 @@ module Liquid
input = Time.at(input.to_i)
end
date = input.is_a?(String) ? Time.parse(input) : input
date =
if input.is_a?(String)
case input.downcase
when 'now', 'today' then Time.now
else
Time.parse(input)
end
else
input
end
if date.respond_to?(:strftime)
date.strftime(format.to_s)

View File

@@ -103,6 +103,8 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_equal '07/05/2006', @filters.date("2006-07-05 10:00:00", "%m/%d/%Y")
assert_equal "07/16/2004", @filters.date("Fri Jul 16 01:00:00 2004", "%m/%d/%Y")
assert_equal "#{Date.today.year}", @filters.date('now', '%Y')
assert_equal "#{Date.today.year}", @filters.date('today', '%Y')
assert_equal nil, @filters.date(nil, "%B")