Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions 02.calendar/calendar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby
require "date"
require "optparse"

def create_calendar
opt = OptionParser.new
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

適切にindentしましょうー

target_year = Date.today.year
target_month = Date.today.mon
option = {}

opt.on('-y Integer') do |y|
target_year = y
end

opt.on('-m Integer') do |m|
target_month = m
end
opt.parse!(ARGV)

first_date = Date.new(target_year.to_i, target_month.to_i, 1)
last_date = Date.new(target_year.to_i, target_month.to_i, -1)
day_of_week = first_date.wday

days = []
day_of_week.times do
days.push(" ")
end

1.upto(last_date.day) do |d|
is_single_digit_date = d < 10
if is_single_digit_date
days.push(" #{d}")
else
days.push(d)
end
end

week = days.each_slice(7).to_a
puts first_date.strftime("%B %Y").center(20)
puts ("日 月 火 水 木 金 土")
week.each{ |day| puts day.join(" ") }
end

create_calendar