Problems with dates?


#1

Hello. I’m fairly new to ruby, but hit a snag already. I’m writing a
small .rhtml file that will display a dynamic calendar. Its pretty
basic right now, consisting of a simple html table and some css. I
also wrote a Calendar class, included below, to assist with the task.
The problem is that apache mod_ruby segfaults! I’ve tried running via
the command-line with both erb and eruby. erb corrupts the output,
putting the dynamically generated stuff at the top, above the static
html code. eruby seems to handle it fine most of the time, but I have
seen errors from it as well, reporting an error at
/usr/lib/ruby/1.8/date.rb line 305. I’m running apache 2.0.54, ruby
1.8.3, mod_ruby 1.2.4 on Gentoo Linux.

Thanks in advance,
Russ

<% require ‘date’; require ‘calendar’ %><?xml version=“1.0”
encoding=“UTF-8”?>

Date Test
<% d = Date.today %> <%= Date::MONTHNAMES[d.month] + ' ' + d.year.to_s %> <% Date::TINY_DAYNAMES.each do |name| %> <% end %> <% cal = Calendar.new(Date.today.year) mo = cal.getMonth(Date.today.month) for weeks in 0...mo.length wk = mo[weeks] print '' for dy in 0...wk.length style = Array.new title = nil if (wk[dy] == Date.today) style.push 'today' title = 'today' end style.push 'other' if (wk[dy].month != Date.today.month) print ' 0) print ' title="' + title + '"' if (title) print '>' + wk[dy].day.to_s + '' end puts '' end %>
<%= name %>

/usr/lib/ruby/site-ruby/calendar.rb:
require ‘date’

class Date
TINY_DAYNAMES = %w(S M T W T F S)
end

class Calendar
def initialize(year=Date.today.year)
@year = year
end

def add(event)
list = allEvents[event.date]
list = Array.new if (!list)
list.push(event)
allEvents[event.date] = list
monEvents = @monthly[event.date.month]
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