指定の日までの日数を表示
#! /usr/local/bin/ruby
today = Time.now #今日の日時取得
targetM = 12 #指定月
targetD = 25 #指定日
targetY = today.year
if today.month < targetM or (today.month == targetM and today.day <= targetD)
target = Time.local(targetY, targetM, targetD) #指定の日の日時取得
count = target.yday - today.yday #指定の日までの日数
else #指定の日を過ぎている場合
target = Time.local(targetY + 1, targetM, targetD) #指定の日の日時取得(来年)
lastday = Time.local(targetY, 12, 31) #今年最後の日の日時取得
count = target.yday + lastday.yday - today.yday #指定の日までの日数(来年)
end
print "Content-type: text/html\n\n"
print <<END
<html>
<head>
<title>指定の日までの日数</title>
</head>
<body>
END
if count == 0
print "メリークリスマス!!"
else
print "クリスマスまであと #{count}日 です。"
end
print <<END
<br>
</body>
</html>
END
exit
〔 実行する 〕