Merge pull request #3299 from ryanburnette/fix_date
This commit is contained in:
commit
763118a381
|
@ -1,5 +1,6 @@
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'date'
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module Filters
|
module Filters
|
||||||
|
@ -302,6 +303,8 @@ module Jekyll
|
||||||
case input
|
case input
|
||||||
when Time
|
when Time
|
||||||
input
|
input
|
||||||
|
when Date
|
||||||
|
input.to_time
|
||||||
when String
|
when String
|
||||||
Time.parse(input) rescue Time.at(input.to_i)
|
Time.parse(input) rescue Time.at(input.to_i)
|
||||||
when Numeric
|
when Numeric
|
||||||
|
|
|
@ -17,6 +17,7 @@ class TestFilters < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@filter = JekyllFilter.new({"source" => source_dir, "destination" => dest_dir, "timezone" => "UTC"})
|
@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)
|
||||||
|
@sample_date = Date.parse("2013-03-27")
|
||||||
@time_as_string = "September 11, 2001 12:46:30 -0000"
|
@time_as_string = "September 11, 2001 12:46:30 -0000"
|
||||||
@time_as_numeric = 1399680607
|
@time_as_numeric = 1399680607
|
||||||
@array_of_objects = [
|
@array_of_objects = [
|
||||||
|
@ -80,6 +81,24 @@ class TestFilters < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with Date object" do
|
||||||
|
should "format a date with short format" do
|
||||||
|
assert_equal "27 Mar 2013", @filter.date_to_string(@sample_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "format a date with long format" do
|
||||||
|
assert_equal "27 March 2013", @filter.date_to_long_string(@sample_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "format a time with xmlschema" do
|
||||||
|
assert_equal "2013-03-27T00:00:00+00:00", @filter.date_to_xmlschema(@sample_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "format a time according to RFC-822" do
|
||||||
|
assert_equal "Wed, 27 Mar 2013 00:00:00 +0000", @filter.date_to_rfc822(@sample_date)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with String object" do
|
context "with String object" do
|
||||||
should "format a date with short format" do
|
should "format a date with short format" do
|
||||||
assert_equal "11 Sep 2001", @filter.date_to_string(@time_as_string)
|
assert_equal "11 Sep 2001", @filter.date_to_string(@time_as_string)
|
||||||
|
|
Loading…
Reference in New Issue