Parse strings into Time objects for date-related parsing. Fixes #997.
This commit is contained in:
parent
1c4f5b4ee5
commit
7554c4ce61
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue