#!/usr/local/bin/ruby # html calendar # (C) 2005-2006 Sato Makoto #2005年11月30日 (水) 11:16:29 JST # 原型。タグ付で標準出力。 # Wed Aug 30 15:31:37 JST 2006 # cgi化  と
によるレイアウトをtableに変更。 require 'date' # http header print "Content-type: text/html\n\n" # html header def header print < カレンダー EOF end # html footer def footer print "
" end EMPTY=" " fday=1 date=DateTime.now # What day of the week in the # first day of this month? # 0-> Sun, 1 -> Mon, ... fday_month = DateTime.new(date.year,date.month,fday).wday # leap year? l_year = Date.leap?(date.year) # the last day of this month lastday=[28,29,30,31] case date.month when 1,3,5,7,8,10,12 then last=lastday[3] when 4,6,9,11 then last=lastday[2] else if l_year then last=lastday[1] else last=lastday[0] end end header print "\n" print "

\n" print date.year ," 年 ", date.month ," 月 ", date.day ," 日\n" print "

\n" print "\n" print "" # print week weeks = ["日","月","火","水","木","金","土"] weeks.each{|i| print "" } print "\n" # shift the first day of this month fday_month.times { print "" } # print days shift=fday_month for i in fday..last print "" shift+=1 if i == date.day then print '" end if shift % 7 ==0 then print "\n" end end print "\n" print "
",i,"
",EMPTY,"",i,"',i,"
\n" footer