diff --git a/src/FormattingTrait.php b/src/FormattingTrait.php index 33a1f31b..edb52916 100644 --- a/src/FormattingTrait.php +++ b/src/FormattingTrait.php @@ -236,6 +236,8 @@ public function toUnixString(): string /** * Returns the quarter * + * Deprecated 3.3.0: The $range parameter is deprecated. Use toQuarterRange() for quarter ranges. + * * @param bool $range Range. * @return array|int 1, 2, 3, or 4 quarter of year or array if $range true */ @@ -246,7 +248,24 @@ public function toQuarter(bool $range = false): int|array return $quarter; } + trigger_error( + 'Using toQuarter() with `$range=true` is deprecated. Use `toQuarterRange()` instead.', + E_USER_DEPRECATED + ); + + return $this->toQuarterRange(); + } + + /** + * Returns the quarter range + * + * @return array Array with start and end date of quarter in Y-m-d format + */ + public function toQuarterRange(): array + { + $quarter = (int)ceil((int)$this->format('m') / 3); $year = $this->format('Y'); + switch ($quarter) { case 1: return [$year . '-01-01', $year . '-03-31'];