Class: Date
Overview
Date
Ruby’s standard Date class with a few extensions.
Instance Method Summary collapse
-
#days_in_month ⇒ Object
Returns the number of days in the date’s month.
- #days_of_month ⇒ Object
-
#stamp(format = nil) ⇒ Object
(also: #to_s)
An enhanched #to_s method that cane take an optional format flag of :short or :long.
-
#to_date ⇒ Object
To be able to keep Dates and Times interchangeable on conversions.
-
#to_time(form = :local) ⇒ Object
Convert Date to Time.
Instance Method Details
#days_in_month ⇒ Object
Returns the number of days in the date’s month.
Date.new(2004,2).days_in_month #=> 28
– Credit goes to Ken Kunz. ++
70 71 72 |
# File 'lib/more/facets/date.rb', line 70 def days_in_month Date.civil(year, month, -1).day end |
#days_of_month ⇒ Object
74 75 76 |
# File 'lib/more/facets/date.rb', line 74 def days_of_month (1..days_in_month).to_a end |
#stamp(format = nil) ⇒ Object Also known as: to_s
An enhanched #to_s method that cane take an optional format flag of :short or :long.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/more/facets/date.rb', line 49 def stamp(format = nil) case format when :short strftime("%e %b").strip when :long strftime("%B %e, %Y").strip else strftime("%Y-%m-%d") # standard to_s end end |
#to_date ⇒ Object
To be able to keep Dates and Times interchangeable on conversions.
37 38 39 |
# File 'lib/more/facets/date.rb', line 37 def to_date self end |
#to_time(form = :local) ⇒ Object
Convert Date to Time.
43 44 45 |
# File 'lib/more/facets/date.rb', line 43 def to_time(form = :local) ::Time.send(form, year, month, day) end |