fjord/cal.rb
2024-03-07 22:40:32 +09:00

29 lines
607 B
Ruby
Executable file

#!/usr/bin/ruby
require 'date'
require 'optparse'
optmonth = ARGV.getopts('m:')
optyear = ARGV.getopts('y:')
# opt = OptionParser.new
# opt.on('-m')
# opt.on('-y')
# opt.parse!
year = Date.today.year
month = Date.today.month
startwday = Date.new(year, month, 1).wday # その月の最初の曜日
enddate = Date.new(year, month, -1).day # その月の最後の曜日
week = %w[日 月 火 水 木 金 土]
puts "\t#{month}#{year}"
puts week.join(' ')
print ' ' * startwday
days = startwday
(1..enddate).each do |day|
print day.to_s.rjust(2) + ' '
days += 1
print "\n" if days % 7 == 0
end