Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
追加のテストに対応
Browse files Browse the repository at this point in the history
yuki-snow1823 committed Dec 2, 2024
1 parent 9ddfa72 commit 5f77e8e
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/month.rb
Original file line number Diff line number Diff line change
@@ -17,6 +17,10 @@ def last_day
Date.new(@year, @number, -1).day
end

def first_day_of_month?(date)
date.day == Date.new(date.year, @number, 1).day
end

def end_of_month?(date)
date.day == Date.new(date.year, @number, -1).day
end
24 changes: 16 additions & 8 deletions lib/sg_strange_calendar.rb
Original file line number Diff line number Diff line change
@@ -77,22 +77,30 @@ def generate_days_in_month(month, today_marker: false)
days_in_month[start_day + d - 1] = d.to_s.rjust(2, ' ')
end

days_in_month[@today.day + start_day - 1] = "[#{@today.day}]" if today_marker
days_in_month[@today.day + start_day - 1] = "[#{@today.day}]".rjust(4, ' ') if today_marker
days_in_month
end

def display_days_in_month(month, days_in_month, leading_spaces, today_marker: false)
if today_marker
if today_marker
start_day = month.start_wday
days_in_month_until_today = days_in_month[0..@today.day + start_day - 1]
days_in_month_after_today = days_in_month[@today.day + start_day..-1]

if month.end_of_month?(@today)
"#{month.name} #{leading_spaces}#{days_in_month_until_today[0..-2].join(' ')}#{days_in_month_until_today.last}"
days_in_month_until_today = days_in_month[0..(start_day + @today.day - 2)]
days_today = days_in_month[start_day + @today.day - 1]
days_in_month_after_today = days_in_month[start_day + @today.day..-1]

if month.first_day_of_month?(@today) && month.start_wday == 0
days_in_month_until_today = days_in_month[0..(start_day + @today.day - 1)]
"#{month.name}#{leading_spaces}#{days_in_month_until_today.join(' ')}#{days_in_month_after_today.join(' ').rstrip}"
elsif month.first_day_of_month?(@today)
"#{month.name} #{leading_spaces}#{days_in_month_until_today.join(' ')}#{days_today}#{days_in_month_after_today.join(' ').rstrip}"
elsif month.end_of_month?(@today)
"#{month.name} #{leading_spaces}#{days_in_month_until_today[0..-1].join(' ')}#{days_today}"
else
"#{month.name} #{leading_spaces}#{days_in_month_until_today.join(' ')}#{days_in_month_after_today.join(' ').rstrip}"

"#{month.name} #{leading_spaces}#{days_in_month_until_today.join(' ')}#{days_today}#{days_in_month_after_today.join(' ').rstrip}"
end
else

"#{month.name} #{leading_spaces}#{days_in_month.join(' ').rstrip}"
end
end
1 change: 0 additions & 1 deletion test/sg_strange_calendar_test.rb
Original file line number Diff line number Diff line change
@@ -107,7 +107,6 @@ def test_level_2_for_2025_03_31
end

def test_level_2_all
skip "レベル2にチャレンジする人はこの行を削除してください"
file_path = File.expand_path('level2.txt', File.dirname(__FILE__))
calendars = File.read(file_path).lines.each_slice(13).map(&:join).map(&:chomp)
from_date = Date.new(2025, 1, 1)

0 comments on commit 5f77e8e

Please sign in to comment.