Class: Date

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#bump(attr, amount = nil) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/tickle.rb', line 111

def bump(attr, amount=nil)
  amount ||= 1
  case attr
  when :day then
    self + 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))
    self + diff
  when :week then
    self + (7*amount)
  when :month then
    self>>amount
  when :year then
    Date.civil(self.year + amount, self.month, self.day)
  else
          raise Exception, "type \"#{attr}\" not supported."
  end
end

#days_in_monthObject

returns the days in the sending month



105
106
107
108
109
# File 'lib/tickle.rb', line 105

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

#to_dateObject



26
27
28
# File 'lib/tickle.rb', line 26

def to_date
  self
end

#to_time(form = :local) ⇒ Object



30
31
32
# File 'lib/tickle.rb', line 30

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