Skip to content
Draft
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
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ parameters:
- identifier: missingType.iterableValue
- identifier: property.readOnlyByPhpDocDefaultValue
- identifier: property.readOnlyByPhpDocAssignNotInConstructor
-
message: "#^Call to an undefined static method DateTimeImmutable\\:\\:createFromTimestamp\\(\\)\\.$#"
count: 1
path: src/Chronos.php
-
message: "#with generic class DatePeriod but does not specify its types: TDate, TEnd, TRecurrences$#"
count: 1
Expand Down
7 changes: 5 additions & 2 deletions src/Chronos.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@
/**
* Format to use for __toString method when type juggling occurs.
*
* @var string
* The widened type allows subclasses (like CakePHP I18n classes) to use
* IntlDateFormatter constants while maintaining backward compatibility.
*
* @var array|string|int
*/
protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;
protected static array|string|int $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;
Copy link
Contributor

@LordSimal LordSimal Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this considered a breaking change for non cakephp apps using this?

Copy link
Member Author

@dereuromark dereuromark Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats BC breaking why this is targeting 4x, see milestone and PR descr.
Same as deprecation removal etc is.

But no, not for Cake Apps, explained above.


/**
* Days of weekend
Expand Down Expand Up @@ -742,7 +745,7 @@
*/
public static function createFromTimestamp(float|int $timestamp, DateTimeZone|string|null $timezone = null): static
{
$instance = PHP_VERSION_ID >= 80400 ? parent::createFromTimestamp($timestamp) : new static('@' . $timestamp);

Check failure on line 748 in src/Chronos.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Call to an undefined static method DateTimeImmutable::createFromTimestamp().

return $timezone ? $instance->setTimezone($timezone) : $instance;
}
Expand Down
7 changes: 5 additions & 2 deletions src/ChronosDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ class ChronosDate implements Stringable
/**
* Format to use for __toString method when type juggling occurs.
*
* @var string
* The widened type allows subclasses (like CakePHP I18n classes) to use
* IntlDateFormatter constants while maintaining backward compatibility.
*
* @var array|string|int
*/
protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;
protected static array|string|int $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;

/**
* Names of days of the week.
Expand Down
9 changes: 7 additions & 2 deletions src/ChronosTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ class ChronosTime implements Stringable
/**
* Format to use for __toString method.
*
* @var string
* The widened type allows subclasses to use IntlDateFormatter constants
* while maintaining backward compatibility.
*
* @var array|string|int
*/
protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;
protected static array|string|int $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;

/**
* @var int
Expand Down Expand Up @@ -381,6 +384,8 @@ public static function setToStringFormat(string $format): void
*/
public function __toString(): string
{
assert(is_string(static::$toStringFormat));

return $this->format(static::$toStringFormat);
}

Expand Down
25 changes: 8 additions & 17 deletions src/FormattingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
/**
* Provides string formatting methods for datetime instances.
*
* Expects implementing classes to define static::$toStringFormat
* Expects implementing classes to define static::$toStringFormat as `array|string|int`.
* The widened type allows subclasses (like CakePHP I18n classes) to use
* IntlDateFormatter constants while maintaining backward compatibility.
*
* @internal
*/
Expand Down Expand Up @@ -54,6 +56,8 @@ public static function setToStringFormat(string $format): void
*/
public function __toString(): string
{
assert(is_string(static::$toStringFormat));

return $this->format(static::$toStringFormat);
}

Expand Down Expand Up @@ -236,24 +240,11 @@ 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
* @return int 1, 2, 3, or 4 quarter of year
*/
public function toQuarter(bool $range = false): int|array
public function toQuarter(): int
{
$quarter = (int)ceil((int)$this->format('m') / 3);
if ($range === false) {
return $quarter;
}

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

return $this->toQuarterRange();
return (int)ceil((int)$this->format('m') / 3);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/TestCase/DateTime/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function toQuarterProvider()
* @return void
*/
#[DataProvider('toQuarterProvider')]
public function testToQuarter($date, $expected, $range = false)
public function testToQuarter($date, $expected)
{
$this->assertSame($expected, (new Chronos($date))->toQuarter());
}
Expand All @@ -205,9 +205,6 @@ public static function toQuarterRangeProvider()
public function testToQuarterRange($date, $expected)
{
$this->assertSame($expected, (new Chronos($date))->toQuarterRange());
$this->deprecated(function () use ($date, $expected) {
$this->assertSame($expected, (new Chronos($date))->toQuarter(true));
});
}

/**
Expand Down
Loading