R
Russ Pridemore
I'm having difficulty with a small program I'm writing dealing with
dates. I've written the calendar class below. It works just fine
when calling getMonth for all months EXCEPT NOVEMBER. Interrupting
the call while in irb shows that it is busy in the reduce method of
Rational, called from Date. Any ideas?
Thanks,
Russ
require 'date'
class Calendar
def initialize(year=Date.today.year)
@year = year
end
def getMonth(mo)
dt = Date.new(@year, mo, 1)
i = dt.month
list = Array.new
while i != (mo+1) % 12
wk = getWeek(dt.month, dt.day)
dt = wk[6].succ
i = dt.month
list.push(wk)
end
list
end
def getWeek(mo, dy)
dt = Date.new(@year, mo, dy)
dt -= dt.wday
list = Array.new
for i in 0..6
list.push dt
dt = dt.succ
end
list
end
def getDay(mo, dy)
Date.new(@year, mo, dy)
end
end
dates. I've written the calendar class below. It works just fine
when calling getMonth for all months EXCEPT NOVEMBER. Interrupting
the call while in irb shows that it is busy in the reduce method of
Rational, called from Date. Any ideas?
Thanks,
Russ
require 'date'
class Calendar
def initialize(year=Date.today.year)
@year = year
end
def getMonth(mo)
dt = Date.new(@year, mo, 1)
i = dt.month
list = Array.new
while i != (mo+1) % 12
wk = getWeek(dt.month, dt.day)
dt = wk[6].succ
i = dt.month
list.push(wk)
end
list
end
def getWeek(mo, dy)
dt = Date.new(@year, mo, dy)
dt -= dt.wday
list = Array.new
for i in 0..6
list.push dt
dt = dt.succ
end
list
end
def getDay(mo, dy)
Date.new(@year, mo, dy)
end
end