Class: Date

Inherits:
Object show all
Includes:
DateAndTimeFormatting
Defined in:
merb-helpers/lib/merb-helpers/core_ext.rb

Instance Method Summary collapse

Methods included from DateAndTimeFormatting

included

Instance Method Details

#formatted(format = :default) ⇒ Object



25
26
27
28
29
30
31
32
# File 'merb-helpers/lib/merb-helpers/core_ext.rb', line 25

def formatted(format=:default)
  format = Date.formats[format] 
  if format.nil?
    self.to_s 
  else
    self.strftime(format)
  end
end

#to_dateObject



23
# File 'merb-helpers/lib/merb-helpers/core_ext.rb', line 23

def to_date; self; end

#to_time(form = :utc) ⇒ Object

Converts a Date instance to a Time, where the time is set to the beginning of the day.

Examples:

date = Date.new(2007, 11, 10)
date.to_s                      # => 2007-11-10

date.to_time                   # => Sat Nov 10 00:00:00 UTC 2007
date.to_time(:utc)             # => Sat Nov 10 00:00:00 UTC 2007
date.to_time(:local)           # => Sat Nov 10 00:00:00 -0800 2007


19
20
21
# File 'merb-helpers/lib/merb-helpers/core_ext.rb', line 19

def to_time(form = :utc)
  ::Time.send("#{form}", year, month, day)
end