Skip to content

Loading…

Added date_to_rfc822 used on RSS feeds #892

Merged
merged 2 commits into from

4 participants

@rafaelrosafu

According to the W3C RSS Feed Validator, feeds must format dates as described
on RFC-822 to be valid. Refer to their site to get more info:
http://feedvalidator.org/docs/error/InvalidRFC2822Date.html

I also added a couple of missing unit tests to the other date filters

@rafaelrosafu rafaelrosafu Added filter date_to_rfc822
According to the W3C RSS Feed Validator, feeds must format dates as described
on RFC-822 to be valid. Refer to their site to get more info:
http://feedvalidator.org/docs/error/InvalidRFC2822Date.html

I also added a couple of missing unit tests to the other date filters
186b68a
@mattr-
Jekyll member

:+1:

@rafaelrosafu

It's breaking on Ruby 1.9.3, I'll fix by tomorrow, sorry

@mojombo

+1

@parkr parkr merged commit 7b36d26 into jekyll:master

1 check passed

Details default The Travis build passed
@parkr parkr added a commit that referenced this pull request
@parkr parkr Update history to reflect merge of #892. ccf9d19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2013
  1. @rafaelrosafu

    Added filter date_to_rfc822

    rafaelrosafu committed
    According to the W3C RSS Feed Validator, feeds must format dates as described
    on RFC-822 to be valid. Refer to their site to get more info:
    http://feedvalidator.org/docs/error/InvalidRFC2822Date.html
    
    I also added a couple of missing unit tests to the other date filters
Commits on Mar 29, 2013
  1. @rafaelrosafu
Showing with 31 additions and 0 deletions.
  1. +14 −0 lib/jekyll/filters.rb
  2. +17 −0 test/test_filters.rb
View
14 lib/jekyll/filters.rb
@@ -56,6 +56,20 @@ def date_to_xmlschema(date)
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.
#
View
17 test/test_filters.rb
@@ -13,6 +13,7 @@ def initialize
context "filters" do
setup do
@filter = JekyllFilter.new
+ @sample_time = Time.utc(2013, 03, 27, 11, 22, 33)
end
should "textilize with simple string" do
@@ -42,6 +43,22 @@ def initialize
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:33Z", @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 "&lt;code&gt;command &amp;lt;filename&amp;gt;&lt;/code&gt;", @filter.xml_escape("<code>command &lt;filename&gt;</code>")
Something went wrong with that request. Please try again.