Accept Numeric values for dates.

This commit is contained in:
Parker Moore 2014-05-09 23:11:05 -04:00
parent 53b2e1372c
commit af9f1e6f48
2 changed files with 21 additions and 2 deletions

View File

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

View File

@ -13,9 +13,10 @@ class TestFilters < Test::Unit::TestCase
context "filters" do context "filters" do
setup 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) @sample_time = Time.utc(2013, 03, 27, 11, 22, 33)
@time_as_string = "September 11, 2001 12:46:30 -0000" @time_as_string = "September 11, 2001 12:46:30 -0000"
@time_as_numeric = 1399680607
@array_of_objects = [ @array_of_objects = [
{ "color" => "red", "size" => "large" }, { "color" => "red", "size" => "large" },
{ "color" => "red", "size" => "medium" }, { "color" => "red", "size" => "medium" },
@ -86,6 +87,24 @@ class TestFilters < Test::Unit::TestCase
assert_equal "Tue, 11 Sep 2001 12:46:30 -0000", @filter.date_to_rfc822(@time_as_string) assert_equal "Tue, 11 Sep 2001 12:46:30 -0000", @filter.date_to_rfc822(@time_as_string)
end end
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_equal "2014-05-10T00:10:07Z", @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 end
should "escape xml with ampersands" do should "escape xml with ampersands" do