diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 37d4f1cb..1886194b 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -30,7 +30,7 @@ module Jekyll # # Returns the formatting String. def date_to_string(date) - date.strftime("%d %b %Y") + time(date).strftime("%d %b %Y") end # Format a date in long format e.g. "27 January 2011". @@ -39,7 +39,7 @@ module Jekyll # # Returns the formatted String. def date_to_long_string(date) - date.strftime("%d %B %Y") + time(date).strftime("%d %B %Y") end # Format a date for use in XML. @@ -53,7 +53,7 @@ module Jekyll # # Returns the formatted String. def date_to_xmlschema(date) - date.xmlschema + time(date).xmlschema end # Format a date according to RFC-822 @@ -67,7 +67,7 @@ module Jekyll # # Returns the formatted String. def date_to_rfc822(date) - date.rfc822 + time(date).rfc822 end # XML escape a string for use. Replaces any special characters with @@ -137,5 +137,18 @@ module Jekyll "#{array[0...-1].join(', ')}, #{connector} #{array[-1]}" end end + + private + def time(input) + case input + when Time + input + when String + Time.parse(input) + else + Jekyll::Logger.error "Invalid Date:", "'#{input}' is not a valid datetime." + exit(1) + end + end end end