From 79512ffa8b18f65a0347e41b537b3942ec711001 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Sat, 18 Jul 2026 17:22:44 +0900 Subject: [PATCH 1/5] Add my-calendar --- 02.calendar/my-calendar.rb | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 02.calendar/my-calendar.rb diff --git a/02.calendar/my-calendar.rb b/02.calendar/my-calendar.rb new file mode 100755 index 0000000000..b78e418c33 --- /dev/null +++ b/02.calendar/my-calendar.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby + +require "date" +require "optparse" + +default_year = Date.today.year.to_s +default_month = Date.today.month.to_s + +options = ARGV.getopts("y:m:", "y:#{default_year}", "m:#{default_month}") +year = options["y"].to_i +month = options["m"].to_i + +first_day = Date.new(year, month, 1) +last_day = Date.new(year, month, -1) + +# 年月を出力 +month_year = first_day.strftime(format = "%B") + " " + first_day.strftime(format = "%G") +puts month_year.center(20) + +# 曜日を出力 +puts "Su Mo Tu We Th Fr Sa" + +# 日を出力 +(first_day..last_day).each do |d| + if d.day == 1 + print d.day.to_s.rjust(2 + first_day.wday * 3) + if d.saturday? + print "\n" + end + next + end + + if d.saturday? + print d.day.to_s.rjust(3) + "\n" + elsif d.sunday? + print d.day.to_s.rjust(2) + else + print d.day.to_s.rjust(3) + end + + if d == last_day + print "\n" + end +end + From 610e2eb0a1c1a78ae6f761f1a93985fe115951e4 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Sat, 18 Jul 2026 22:37:14 +0900 Subject: [PATCH 2/5] Rename my-calendar.rb to cal.rb --- 02.calendar/{my-calendar.rb => cal.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 02.calendar/{my-calendar.rb => cal.rb} (100%) diff --git a/02.calendar/my-calendar.rb b/02.calendar/cal.rb similarity index 100% rename from 02.calendar/my-calendar.rb rename to 02.calendar/cal.rb From a2e0ed1bf092d631c76409903e1264d94f119a74 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Mon, 20 Jul 2026 00:25:43 +0900 Subject: [PATCH 3/5] Change English notation to Japanese notation --- 02.calendar/cal.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/02.calendar/cal.rb b/02.calendar/cal.rb index b78e418c33..b86f021c64 100755 --- a/02.calendar/cal.rb +++ b/02.calendar/cal.rb @@ -13,12 +13,11 @@ first_day = Date.new(year, month, 1) last_day = Date.new(year, month, -1) -# 年月を出力 -month_year = first_day.strftime(format = "%B") + " " + first_day.strftime(format = "%G") -puts month_year.center(20) +# タイトルを出力 +puts (month.to_s + "月" + " " + year.to_s).center(20) # 曜日を出力 -puts "Su Mo Tu We Th Fr Sa" +puts "日 月 火 水 木 金 土" # 日を出力 (first_day..last_day).each do |d| From ff328a994d4bc9803d87c37346f499095a3ae105 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Tue, 21 Jul 2026 01:32:03 +0900 Subject: [PATCH 4/5] Change the arguments of the getopts method. --- 02.calendar/cal.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/02.calendar/cal.rb b/02.calendar/cal.rb index b86f021c64..3ce153427a 100755 --- a/02.calendar/cal.rb +++ b/02.calendar/cal.rb @@ -6,9 +6,9 @@ default_year = Date.today.year.to_s default_month = Date.today.month.to_s -options = ARGV.getopts("y:m:", "y:#{default_year}", "m:#{default_month}") -year = options["y"].to_i -month = options["m"].to_i +options = ARGV.getopts("y:m:") +year = (options["y"] || Date.today.year.to_s).to_i +month = (options["m"] || Date.today.month.to_s).to_i first_day = Date.new(year, month, 1) last_day = Date.new(year, month, -1) From ed380ddedd9848ed9514cd04941dedca6bcb78d7 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Wed, 22 Jul 2026 17:02:59 +0900 Subject: [PATCH 5/5] Remove unnecessary variables. --- 02.calendar/cal.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/02.calendar/cal.rb b/02.calendar/cal.rb index 3ce153427a..716f63b17a 100755 --- a/02.calendar/cal.rb +++ b/02.calendar/cal.rb @@ -3,9 +3,6 @@ require "date" require "optparse" -default_year = Date.today.year.to_s -default_month = Date.today.month.to_s - options = ARGV.getopts("y:m:") year = (options["y"] || Date.today.year.to_s).to_i month = (options["m"] || Date.today.month.to_s).to_i