mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user