################################################# ## ## Calender Ver.0.1 (C) NAWATE, M. ## ## Use this script as following manner. ## ## $ ruby cal_with_date.rb 2007 7 ## ## You need two arguments indicating year and month. ## ################################################## require 'date' year = ARGV[0].to_i mon = ARGV[1].to_i ################################################## ## ## Count the days of the month interested ## ################################################## if mon == 12 days_of_the_month = Date.new(year+1,1,1) - Date.new(year,mon,1) else days_of_the_month = Date.new(year,mon+1,1) - Date.new(year,mon,1) end ################################################## ## ## Find what day of the week the first day of the month is ## ################################################## day_of_the_week = Date.new(year,mon,1).wday ################################################## ## ## Prepare for the headers of the calendar ## ################################################## month = ["", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] printf "\n %s %s\n\n", year, month[mon] printf " SU MO TU WE TH FR SA\n" ################################################## ## ## Put spaces in the first line before the first day ## ################################################## sp = " " for i in 0..day_of_the_week-1 printf "%3s", sp end ################################################## ## ## Print the dates ## ################################################## for i in 1..days_of_the_month printf "%3d", i if i % 7 == (7 - day_of_the_week) % 7 printf "\n" end end ################################################## ## ## Finish ## ################################################## print "\n"