problems with dates?

R

Russ Pridemore

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.=20
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=3D"1.0" encoding=3D"U=
TF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xht=
ml11/
DTD/xhtml11.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en">
<head>
<title>Date Test</title>
<link rel=3D"stylesheet" type=3D"text/css" href=3D"home.css"/>
</head>
<body>
<div class=3D"content">
<div>
<% d =3D Date.today %>
<table class=3D"calendar"><caption><a href=3D"#"><%=3D Date::MONTHNAMES[d.m=
onth] + ' '
+ d.year.to_s %></a></caption><thead><tr>
<% Date::TINY_DAYNAMES.each do |name| %>
<th><%=3D name %></th> <% end %>
</tr></thead><tbody><tr>
<% cal =3D Calendar.new(Date.today.year)
mo =3D cal.getMonth(Date.today.month)
for weeks in 0...mo.length
wk =3D mo[weeks]
print '<tr>'
for dy in 0...wk.length
style =3D Array.new
title =3D nil
if (wk[dy] =3D=3D Date.today)
style.push 'today'
title =3D 'today'
end
style.push 'other' if (wk[dy].month !=3D Date.today.month)
print '<td'
print ' class=3D"' + style.to_s + '"' if (style.length > 0)
print ' title=3D"' + title + '"' if (title)
print '>' + wk[dy].day.to_s + '</td>'
end
puts '</tr>'
end %>
</tbody></table>
</div>
</div></body></html>

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

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

class Calendar
def initialize(year=3DDate.today.year)
@year =3D year
end

def add(event)
list =3D allEvents[event.date]
list =3D Array.new if (!list)
list.push(event)
allEvents[event.date] =3D list
monEvents =3D @monthly[event.date.month]
end

def getMonth(mo)
dt =3D Date.new(@year, mo, 1)
i =3D dt.month
list =3D Array.new
while i !=3D (mo+1) % 12
wk =3D getWeek(dt.month, dt.day)
dt =3D wk[6].succ
i =3D dt.month
list.push(wk)
end
list
end

def getWeek(mo, dy)
dt =3D Date.new(@year, mo, dy)
dt -=3D dt.wday
list =3D Array.new
for i in 0..6
list.push dt
dt =3D dt.succ
end
list
end

def getDay(mo, dy)
Date.new(@year, mo, dy)
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top