Add custom date format %o for ordinal representation of the day
This commit is contained in:
parent
987dccee76
commit
142681489f
@ -11,6 +11,7 @@ simple_search: http://google.com/search
|
|||||||
# Default date format is "ordinal" (resulting in "July 22nd 2007")
|
# Default date format is "ordinal" (resulting in "July 22nd 2007")
|
||||||
# You can customize the format as defined in
|
# You can customize the format as defined in
|
||||||
# http://www.ruby-doc.org/core-1.9.2/Time.html#method-i-strftime
|
# http://www.ruby-doc.org/core-1.9.2/Time.html#method-i-strftime
|
||||||
|
# Additionally, %o will give you the ordinal representation of the day
|
||||||
date_format: "ordinal"
|
date_format: "ordinal"
|
||||||
|
|
||||||
# RSS / Email (optional) subscription links (change if using something like Feedburner)
|
# RSS / Email (optional) subscription links (change if using something like Feedburner)
|
||||||
@ -92,6 +93,6 @@ disqus_show_comment_count: false
|
|||||||
|
|
||||||
# Google Analytics
|
# Google Analytics
|
||||||
google_analytics_tracking_id:
|
google_analytics_tracking_id:
|
||||||
|
|
||||||
# Facebook Like
|
# Facebook Like
|
||||||
facebook_like: true
|
facebook_like: true
|
||||||
|
@ -29,12 +29,16 @@ module Octopress
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Formats date either as ordinal or by given date format
|
||||||
|
# Adds %o as ordinal representation of the day
|
||||||
def format_date(date, format)
|
def format_date(date, format)
|
||||||
date = datetime(date)
|
date = datetime(date)
|
||||||
if format.nil? || format.empty? || format == "ordinal"
|
if format.nil? || format.empty? || format == "ordinal"
|
||||||
date_formatted = ordinalize(date)
|
date_formatted = ordinalize(date)
|
||||||
else
|
else
|
||||||
|
format.gsub!(/%o/, '%%o')
|
||||||
date_formatted = date.strftime(format)
|
date_formatted = date.strftime(format)
|
||||||
|
date_formatted.gsub!(/%o/, ordinal(date.strftime('%e').to_i))
|
||||||
end
|
end
|
||||||
date_formatted
|
date_formatted
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user