Module: DateAndTimeFormatting::ClassMethods
- Defined in:
- lib/merb-helpers/date_time_formatting.rb
Constant Summary collapse
- @@formats =
{ :db => "%Y-%m-%d %H:%M:%S", :time => "%H:%M", # 21:12 :date => "%Y-%m-%d", # 2008-12-04 :short => "%d %b %H:%M", # 01 Sep 21:12 :long => "%B %d, %Y %H:%M", :rfc822 => "%a, %d %b %Y %H:%M:%S %z" }
Instance Method Summary collapse
-
#add_format(key, format) ⇒ Object
Adds a date and time format.
-
#formats ⇒ Object
Lists the date and time formats.
-
#reset_formats ⇒ Object
Resets the date and time formats --.
Instance Method Details
#add_format(key, format) ⇒ Object
Adds a date and time format
Because this operation is not thread safe, you should define custom formats when you load you application. The recommended way to do that, is to use the before_app_loads bootloader.
If you want to add a format at runtime, you will need to use a mutex and synchronize it yourself.
Parameters
- key
name of the format
- format
time format to use
Returns
- Hash
a hash with all formats available
Example
Merb::BootLoader.before_app_loads do
Date.add_format(:matt, "%H:%M:%S %Y-%m-%d")
end
--
90 91 92 |
# File 'lib/merb-helpers/date_time_formatting.rb', line 90 def add_format(key, format) formats.merge!({key => format}) end |
#formats ⇒ Object
Lists the date and time formats
Returns
Hash:: a hash with all formats available
61 62 63 |
# File 'lib/merb-helpers/date_time_formatting.rb', line 61 def formats @@formats end |
#reset_formats ⇒ Object
Resets the date and time formats
98 99 100 101 |
# File 'lib/merb-helpers/date_time_formatting.rb', line 98 def reset_formats original_formats = [:db, :time, :short, :date, :long, :long_ordinal, :rfc822] formats = @@formats.delete_if{|format, v| !original_formats.include?(format)} end |