-
Notifications
You must be signed in to change notification settings - Fork 0
Add my-calendar #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
79512ff
610e2eb
a2e0ed1
ff328a9
ed380dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env ruby | ||
|
|
||
| require "date" | ||
| require "optparse" | ||
|
|
||
| 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) | ||
|
|
||
| # タイトルを出力 | ||
| puts (month.to_s + "月" + " " + year.to_s).center(20) | ||
|
|
||
| # 曜日を出力 | ||
| puts "日 月 火 水 木 金 土" | ||
|
|
||
| # 日を出力 | ||
| (first_day..last_day).each do |d| | ||
| if d.day == 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1日目のインデント計算で 他の日は calコマンドと実際に出力を比較して、特に日曜始まりの月(例:2026年2月など)で幅がズレていないか確認してみてください。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1日目のインデント計算を「2 + first_day.wday * 3」としております。 first_dayは、Dateオブジェクトです。 故に日曜だけ幅2となることを考慮しております。 |
||
| 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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ヘッダー行の組み立てを確認してください。
center(20)の幅 20 ですが、calコマンドの出力では曜日行「日 月 火 水 木 金 土」が20文字(半角換算)あり、ヘッダーはその幅に合わせて中央揃えされます。日本語文字は全角なので、centerに渡す幅の計算に注意が必要です。提出物エビデンスの出力を見ると
11月 2026となっており、calコマンドの11月 2026と大体合っているように見えますが、Rubyのcenterはバイト数や文字数の扱いが全角/半角混在時に想定と異なる場合があります。さまざまな月(1桁月・2桁月)で calコマンドと並べて確認してみてください。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
提出エビデンスはターミナルの出力結果のテキストをコピペしただけでしたので、提出エビデンスの貼り付け先のWebの使用フォントにより微妙にヘッダー部分と日のデータ部分がずれているように見えておりました。先ほど、ターミナルの出力結果の画像キャプチャを貼り付けました。ヘッダー部分と日のデータ部分はずれておりません。また、calコマンドと同じ出力結果となっております。