class Date
def to_fs(format = :default)
Date::DATE_FORMATS[:month_and_year] = '%B %Y'
# config/initializers/date_formats.rb
or Proc instance that takes a date argument as the value.
Use the format name as the hash key and either a strftime string
You can add your own formats to the Date::DATE_FORMATS hash.
== Adding your own date formats to to_fs
date.to_fs(:iso8601) # => "2007-11-10"
date.to_fs(:rfc822) # => "10 Nov 2007"
date.to_fs(:long_ordinal) # => "November 10th, 2007"
date.to_fs(:long) # => "November 10, 2007"
date.to_fs(:number) # => "20071110"
date.to_fs(:short) # => "10 Nov"
date.to_formatted_s(:db) # => "2007-11-10"
date.to_fs(:db) # => "2007-11-10"
date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
This method is aliased to to_formatted_s.
Convert to a formatted string. See DATE_FORMATS for predefined formats.
def to_fs(format = :default) if formatter = DATE_FORMATS[format] if formatter.respond_to?(:call) formatter.call(self).to_s else strftime(formatter) end else to_default_s end end