Skip to content

Commit

Permalink
Fix broken month view if last week of December is in next year
Browse files Browse the repository at this point in the history
The cause was using the wrong character in formatting the year.
We now switch from `Y` to `o` which will work based on the week instead
of date. This is necessary as we provide this year to the week, and
therefore need the year of the week, not day.

Resolves: #11388
  • Loading branch information
d-s-codappix committed Sep 16, 2024
1 parent 0332017 commit a2d7242
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getWeeks(): array
while ($currentDay <= $lastDay) {
$this->weeks[] = new Week(
(int) $currentDay->format('W'),
(int) $currentDay->format('Y')
(int) $currentDay->format('o')
);

$currentDay = $currentDay->modify('+7 days');
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Week.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getPreviousWeek(): Week

return new self(
(int) $newDay->format('W'),
(int) $newDay->format('Y')
(int) $newDay->format('o')
);
}

Expand All @@ -90,7 +90,7 @@ public function getNextWeek(): Week

return new self(
(int) $newDay->format('W'),
(int) $newDay->format('Y')
(int) $newDay->format('o')
);
}

Expand Down
33 changes: 33 additions & 0 deletions Documentation/Changelog/1.1.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1.1.1
=====

Breaking
--------

Nothing

Features
--------

Nothing

Fixes
-----

* Fix broken month view if last week of December is in next year.

The cause was using the wrong character in formatting the year.
We now switch from `Y` to `o` which will work based on the week instead of date.
This is necessary as we provide this year to the week,
and therefore need the year of the week, not day.

Tasks
-----

Nothing

Deprecation
-----------

Nothing

22 changes: 22 additions & 0 deletions Tests/Unit/Domain/Model/MonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ public function returnsAllDaysOfTheFebruaryMonth2021(): void
self::assertSame('2021-02-28', $result[27]->getDateTimeInstance()->format('Y-m-d'));
}

/**
* @test
*/
public function returnsWeeksIfLastDecemberWeekIsInNextYear(): void
{
$subject = new Month(12, 2024);

$result = $subject->getWeeks();

self::assertCount(6, $result);

$week = array_pop($result);
$days = $week->getDays();
self::assertSame('2024-12-30', $days[0]->getDateTimeInstance()->format('Y-m-d'));
self::assertSame('2025-01-05', $days[6]->getDateTimeInstance()->format('Y-m-d'));

$week = array_pop($result);
$days = $week->getDays();
self::assertSame('2024-12-23', $days[0]->getDateTimeInstance()->format('Y-m-d'));
self::assertSame('2024-12-29', $days[6]->getDateTimeInstance()->format('Y-m-d'));
}

/**
* @test
*/
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'state' => 'alpha',
'uploadfolder' => 0,
'clearCacheOnLoad' => 0,
'version' => '1.1.0',
'version' => '1.1.1',
'constraints' => [
'depends' => [
'typo3' => '*',
Expand Down

0 comments on commit a2d7242

Please sign in to comment.