Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/rosetta_queue/core_ext/time.rb

Constant Summary collapse

DATE_FORMATS =
{
  :db           => "%Y-%m-%d %H:%M:%S",
  :number       => "%Y%m%d%H%M%S",
  :time         => "%H:%M",
  :short        => "%d %b %H:%M",
  :long         => "%B %d, %Y %H:%M",
  :long_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}, %Y %H:%M") },
  :rfc822       => lambda { |time| time.strftime("%a, %d %b %Y %H:%M:%S #{time.formatted_offset(false)}") }
}

Instance Method Summary collapse

Instance Method Details

#to_formatted_s(format = :default) ⇒ Object



15
16
17
18
# File 'lib/rosetta_queue/core_ext/time.rb', line 15

def to_formatted_s(format = :default)
  return to_default_s unless formatter = DATE_FORMATS[format]
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
end