Class: Date

Inherits:
Object show all
Defined in:
lib/nano/date/to_s.rb,
lib/nano/date/stamp.rb,
lib/nano/date/to_date.rb,
lib/nano/date/to_time.rb,
lib/nano/date/days_in_month.rb,
lib/nano/date/days_of_month.rb

Instance Method Summary collapse

Instance Method Details

#days_in_monthObject

Returns the number of days in the date’s month.

Date.new(2004,2).days_in_month #=> 28

– Credit goes to Ken Kunz. ++



10
11
12
# File 'lib/nano/date/days_in_month.rb', line 10

def days_in_month
   Date.civil(year, month, -1).day
end

#days_of_monthObject



3
4
5
# File 'lib/nano/date/days_of_month.rb', line 3

def days_of_month
  (1..days_in_month).to_a
end

#to_dateObject

To be able to keep Dates and Times interchangeable on conversions.



6
7
8
# File 'lib/nano/date/to_date.rb', line 6

def to_date
  self
end

#to_s(format = nil) ⇒ Object Also known as: stamp

An improved #to_s method that cane take an optional format flag of :short or :long.



6
7
8
9
10
11
12
13
14
15
# File 'lib/nano/date/to_s.rb', line 6

def to_s(format = nil)
  case format
  when :short
    strftime("%e %b").strip
  when :long
    strftime("%B %e, %Y").strip
  else
    stamp
  end
end

#to_time(form = :local) ⇒ Object

Convert Date to Time.



7
8
9
# File 'lib/nano/date/to_time.rb', line 7

def to_time(form = :local)
  ::Time.send(form, year, month, day)
end