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

Instance Method Details

#add_format(key, format) ⇒ Object

Adds a date and time format

Parameters

key<Symbol>

name of the format

format<Hash>

time format to use

Returns

Hash

a hash with all formats available

Example

Date.add_format(:matt, "%H:%M:%S %Y-%m-%d")
Time.now.formatted(:matt) # => "00:00:00 2007-11-02"



76
77
78
# File 'lib/merb-helpers/date_time_formatting.rb', line 76

def add_format(key, format)
  formats.merge!({key => format})
end

#formatsObject

Lists the date and time formats

Returns

Hash

a hash with all formats available



56
57
58
# File 'lib/merb-helpers/date_time_formatting.rb', line 56

def formats
  @@formats
end

#reset_formatsObject

Resets the date and time formats –



84
85
86
87
# File 'lib/merb-helpers/date_time_formatting.rb', line 84

def reset_formats
  original_formats = [:db, :time, :short, :date, :long, :long_ordinal, :rfc822]
  formats = @@formats.delete_if{|format, v| !original_formats.include?(format)}
end