Skip to content

Commit

Permalink
Merge pull request #5693 from takeuji/carbon-method-fix
Browse files Browse the repository at this point in the history
carbonのaddDay,addMonthのメソッド呼び出しを修正
  • Loading branch information
chihiro-adachi authored Aug 30, 2022
2 parents 98f34f6 + e3e2d4e commit 198aacb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion codeception/acceptance/EA07BasicinfoCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ public function basicinfo_定休日カレンダー_表示(AcceptanceTester $I)
// 定休日を設定
$holidays = [
'定休日1' => Carbon::now()->day(1), // 今月1日
'定休日2' => Carbon::now()->startOfMonth()->addMonth(1)->day(28), // 翌月28日
'定休日2' => Carbon::now()->startOfMonth()->addMonth()->day(28), // 翌月28日
];

foreach ($holidays as $title => $date) {
Expand Down
6 changes: 3 additions & 3 deletions src/Eccube/Controller/Block/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function index(Request $request)
{
$today = Carbon::now();
$firstDateOfThisMonth = $today->copy()->startOfMonth();
$firstDateOfNextMonth = $today->copy()->startOfMonth()->addMonth(1)->startOfMonth();
$endDateOfNextMonth = $today->copy()->startOfMonth()->addMonth(1)->endOfMonth();
$firstDateOfNextMonth = $today->copy()->startOfMonth()->addMonth()->startOfMonth();
$endDateOfNextMonth = $today->copy()->startOfMonth()->addMonth()->endOfMonth();

// 2ヶ月間の定休日を取得
$HolidaysOfTwoMonths = $this->calendarRepository->getHolidayList($firstDateOfThisMonth, $endDateOfNextMonth);
Expand All @@ -65,7 +65,7 @@ public function index(Request $request)
$thisMonthCalendar = $this->setHolidayAndTodayFlag($thisMonthCalendar, $holidayListOfTwoMonths, $today->copy());

// 来月のカレンダー配列に定休日フラグを設定
$nextMonthCalendar = $this->setHolidayAndTodayFlag($nextMonthCalendar, $holidayListOfTwoMonths, $today->copy()->startOfMonth()->addMonth(1));
$nextMonthCalendar = $this->setHolidayAndTodayFlag($nextMonthCalendar, $holidayListOfTwoMonths, $today->copy()->startOfMonth()->addMonth());

// 各カレンダータイトルを作成
$monthFormat = $this->translator->trans('front.block.calendar.month_format');
Expand Down
28 changes: 14 additions & 14 deletions tests/Eccube/Tests/Web/Block/CalendarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testThisMonthTitle()
public function testNextMonthTitle()
{
$crawler = $this->client->request('GET', $this->generateUrl('block_calendar'));
$this->expected = Carbon::now()->startOfMonth()->addMonth(1)->format('Y年n月');
$this->expected = Carbon::now()->startOfMonth()->addMonth()->format('Y年n月');
$this->actual = $crawler->filter('#next-month-title')->text();
$this->verify();
}
Expand All @@ -58,19 +58,19 @@ public function testTodayAndHolidayStyle()
public function testHolidayStyle()
{
// 土日以外の日を取得
$targetHoliday = Carbon::now()->addDay(1);
$targetHoliday = Carbon::now()->addDay();

if ($targetHoliday->isSaturday()) {
if (!$targetHoliday->copy()->addDay(2)->isCurrentMonth()) {
$targetHoliday = $targetHoliday->addDay(-2);
if (!$targetHoliday->copy()->addDays(2)->isCurrentMonth()) {
$targetHoliday = $targetHoliday->addDays(-2);
} else {
$targetHoliday = $targetHoliday->addDay(2);
$targetHoliday = $targetHoliday->addDays(2);
}
} elseif ($targetHoliday->isSunday()) {
if (!$targetHoliday->copy()->addDay(1)->isCurrentMonth()) {
$targetHoliday = $targetHoliday->addDay(-2);
if (!$targetHoliday->copy()->addDay()->isCurrentMonth()) {
$targetHoliday = $targetHoliday->addDays(-2);
} else {
$targetHoliday = $targetHoliday->addDay(1);
$targetHoliday = $targetHoliday->addDays(1);
}
}

Expand All @@ -97,17 +97,17 @@ public function testWeekendHolidaysStyle()
if ($sundayDayOfWeekNumber == 0) { // Sun
$sunday = $firstDayOfThisMonth->copy();
} elseif ($sundayDayOfWeekNumber == 1) { // Mon
$sunday = $firstDayOfThisMonth->copy()->addDay(6);
$sunday = $firstDayOfThisMonth->copy()->addDays(6);
} elseif ($sundayDayOfWeekNumber == 2) { // Tue
$sunday = $firstDayOfThisMonth->copy()->addDay(5);
$sunday = $firstDayOfThisMonth->copy()->addDays(5);
} elseif ($sundayDayOfWeekNumber == 3) { // Wed
$sunday = $firstDayOfThisMonth->copy()->addDay(4);
$sunday = $firstDayOfThisMonth->copy()->addDays(4);
} elseif ($sundayDayOfWeekNumber == 4) { // Thu
$sunday = $firstDayOfThisMonth->copy()->addDay(3);
$sunday = $firstDayOfThisMonth->copy()->addDays(3);
} elseif ($sundayDayOfWeekNumber == 5) { // Fri
$sunday = $firstDayOfThisMonth->copy()->addDay(2);
$sunday = $firstDayOfThisMonth->copy()->addDays(2);
} elseif ($sundayDayOfWeekNumber == 6) { // Sat
$sunday = $firstDayOfThisMonth->copy()->addDay(1);
$sunday = $firstDayOfThisMonth->copy()->addDays(1);
}
// 日曜の前日が今月かどうかで月初の土曜日を取得
$saturday = null;
Expand Down

0 comments on commit 198aacb

Please sign in to comment.