Merge pull request #2377 from jekyll/numeric

This commit is contained in:
Parker Moore 2014-05-16 03:50:50 -04:00
commit 04b0fe0160
2 changed files with 21 additions and 2 deletions

View File

@ -234,7 +234,7 @@ module Jekyll
input
when String
Time.parse(input) rescue Time.at(input.to_i)
when Number
when Numeric
Time.at(input)
else
Jekyll.logger.error "Invalid Date:", "'#{input}' is not a valid datetime."

View File

@ -15,9 +15,10 @@ class TestFilters < Test::Unit::TestCase
context "filters" do
setup do
@filter = JekyllFilter.new({"source" => source_dir, "destination" => dest_dir})
@filter = JekyllFilter.new({"source" => source_dir, "destination" => dest_dir, "timezone" => "UTC"})
@sample_time = Time.utc(2013, 03, 27, 11, 22, 33)
@time_as_string = "September 11, 2001 12:46:30 -0000"
@time_as_numeric = 1399680607
@array_of_objects = [
{ "color" => "red", "size" => "large" },
{ "color" => "red", "size" => "medium" },
@ -88,6 +89,24 @@ class TestFilters < Test::Unit::TestCase
assert_equal "Tue, 11 Sep 2001 12:46:30 -0000", @filter.date_to_rfc822(@time_as_string)
end
end
context "with a Numeric object" do
should "format a date with short format" do
assert_equal "10 May 2014", @filter.date_to_string(@time_as_numeric)
end
should "format a date with long format" do
assert_equal "10 May 2014", @filter.date_to_long_string(@time_as_numeric)
end
should "format a time with xmlschema" do
assert_match /2014-05-10T00:10:07/, @filter.date_to_xmlschema(@time_as_numeric)
end
should "format a time according to RFC-822" do
assert_equal "Sat, 10 May 2014 00:10:07 +0000", @filter.date_to_rfc822(@time_as_numeric)
end
end
end
should "escape xml with ampersands" do