diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 0384f19c..37d4f1cb 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -56,6 +56,20 @@ module Jekyll date.xmlschema end + # Format a date according to RFC-822 + # + # date - The Time to format. + # + # Examples + # + # date_to_rfc822(Time.now) + # # => "Sun, 24 Apr 2011 12:34:46 +0000" + # + # Returns the formatted String. + def date_to_rfc822(date) + date.rfc822 + end + # XML escape a string for use. Replaces any special characters with # appropriate HTML entity replacements. # diff --git a/test/test_filters.rb b/test/test_filters.rb index 205d4bca..24551bb3 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -13,6 +13,7 @@ class TestFilters < Test::Unit::TestCase context "filters" do setup do @filter = JekyllFilter.new + @sample_time = Time.parse "2013-03-27T11:22:33+00:00" end should "textilize with simple string" do @@ -42,6 +43,22 @@ class TestFilters < Test::Unit::TestCase assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"]) end + should "format a date with short format" do + assert_equal "27 Mar 2013", @filter.date_to_string(@sample_time) + end + + should "format a date with long format" do + assert_equal "27 March 2013", @filter.date_to_long_string(@sample_time) + end + + should "format a time with xmlschema" do + assert_equal "2013-03-27T11:22:33+00:00", @filter.date_to_xmlschema(@sample_time) + end + + should "format a time according to RFC-822" do + assert_equal "Wed, 27 Mar 2013 11:22:33 +0000", @filter.date_to_rfc822(@sample_time) + end + should "escape xml with ampersands" do assert_equal "AT&T", @filter.xml_escape("AT&T") assert_equal "<code>command &lt;filename&gt;</code>", @filter.xml_escape("command <filename>")