Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/timerizer.rb

Overview

Date class monkeywrenched with RelativeTime helpers.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tomorrowObject

Return tomorrow as Date.

See Also:



775
776
777
# File 'lib/timerizer.rb', line 775

def self.tomorrow
  1.day.from_now.to_date
end

.yesterdayObject

Return yesterday as Date.

See Also:



781
782
783
# File 'lib/timerizer.rb', line 781

def self.yesterday
  1.day.ago.to_date
end

Instance Method Details

#at(time) ⇒ Object

Apply a time to a date

Examples:

yesterday at 5:00

Date.yesterday.at(WallClock.new(5, 00, :pm))
  => 2000-1-1 17:00:00 -0800


769
770
771
# File 'lib/timerizer.rb', line 769

def at(time)
  time.to_wall.on(self)
end

#days_in_monthInteger

Return the number of days in a given month.

Examples:

Date.new(2000, 2).days_in_month
  => 29

Returns:

  • (Integer)

    Number of days in the month of the Date.



749
750
751
752
753
754
755
756
757
# File 'lib/timerizer.rb', line 749

def days_in_month
  days_in_feb = (not self.leap?) ? 28 : 29
  number_of_days = [
    31,  days_in_feb,  31,  30,  31,  30,
    31,  31,           30,  31,  30,  31
  ]

  number_of_days.fetch(self.month - 1)
end

#to_dateObject

Return self as Date.

See Also:



761
762
763
# File 'lib/timerizer.rb', line 761

def to_date
  self
end