Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/FormattingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function toQuarter(bool $range = false): int|array

trigger_error(
'Using toQuarter() with `$range=true` is deprecated. Use `toQuarterRange()` instead.',
E_USER_DEPRECATED
E_USER_DEPRECATED,
);

return $this->toQuarterRange();
Expand All @@ -259,23 +259,20 @@ public function toQuarter(bool $range = false): int|array
/**
* Returns the quarter range
*
* @return array<string> Array with start and end date of quarter in Y-m-d format
* @return array{0: string, 1: string} Array with start and end date of quarter in Y-m-d format
*/
public function toQuarterRange(): array
{
/** @var int<1, 4> $quarter */
$quarter = (int)ceil((int)$this->format('m') / 3);
$year = $this->format('Y');

switch ($quarter) {
case 1:
return [$year . '-01-01', $year . '-03-31'];
case 2:
return [$year . '-04-01', $year . '-06-30'];
case 3:
return [$year . '-07-01', $year . '-09-30'];
default:
return [$year . '-10-01', $year . '-12-31'];
}
return match ($quarter) {
1 => [$year . '-01-01', $year . '-03-31'],
2 => [$year . '-04-01', $year . '-06-30'],
3 => [$year . '-07-01', $year . '-09-30'],
4 => [$year . '-10-01', $year . '-12-31'],
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/DateTime/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static function toQuarterRangeProvider()
public function testToQuarterRange($date, $expected)
{
$this->assertSame($expected, (new Chronos($date))->toQuarterRange());
$this->deprecated(function() use ($date, $expected) {
$this->deprecated(function () use ($date, $expected) {
$this->assertSame($expected, (new Chronos($date))->toQuarter(true));
});
}
Expand Down