Class: Date

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#bump(attr, amount = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tickle.rb', line 53

def bump(attr, amount=nil)
  amount ||= 1
  case attr
  when :day then
    Date.civil(self.year, self.month, self.day).next_day(amount)
  when :wday then
    amount = Date::ABBR_DAYNAMES.index(amount) if amount.is_a?(String)
    raise Exception, "specified day of week invalid.  Use #{Date::ABBR_DAYNAMES}" unless amount
    diff = (amount > self.wday) ? (amount - self.wday) : (7 - (self.wday - amount))
    Date.civil(self.year, self.month, self.day).next_day(diff)
  when :week then
    Date.civil(self.year, self.month, self.day).next_day(7*amount)
  when :month then
    Date.civil(self.year, self.month, self.day).next_month(amount)
  when :year then
    Date.civil(self.year, self.month, self.day).next_year(amount)
  else
    raise Exception, "type \"#{attr}\" not supported."
  end
end

#days_in_monthObject

returns the days in the sending month



47
48
49
50
51
# File 'lib/tickle.rb', line 47

def days_in_month
  d,m,y = mday,month,year
  d += 1 while Date.valid_civil?(y,m,d)
  d - 1
end