public
Description: Date and Time localization based on Rails' i18n functionalities
Homepage: http://www.railway.at
Clone URL: git://github.com/clemens/localized_dates.git
localized_dates / lib / core_ext / date.rb
100644 21 lines (18 sloc) 0.594 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
::Date.class_eval do
  def to_formatted_s(format = :default)
    formats = ::Date::DATE_FORMATS
    formatter = formats[format]
 
    unless formatter
      formatters = I18n.translate(:'date.formats', :raise => true) rescue {}
      formatter = formatters[format]
    end
 
    format_to_localize = formatter.respond_to?(:call) ? formatter.call(self) : formatter
    I18n.localize(self, :format => format_to_localize)
  end
  alias_method :to_s, :to_formatted_s
end
 
::Date.const_set('DATE_FORMATS', {
  :db => "%Y-%m-%d",
  :number => "%Y%m%d",
  :rfc822 => "%e %b %Y"
})