# Problems with dates?

**URL:** <https://www.ruby-forum.com/t/problems-with-dates/51317>\
**Category:** Ruby\
**Created:** [December 29, 2005, 4:12pm UTC](https://www.ruby-forum.com/t/problems-with-dates/51317 "2005-12-29T16:12:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russ\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@Russ\_P](https://www.ruby-forum.com/u/Russ_P)\
**Post date:** [December 29, 2005, 4:12pm UTC](https://www.ruby-forum.com/t/problems-with-dates/51317/1 "2005-12-29T16:12:44Z")

</div>

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
