Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling TimeZone::createFromPhpDateTimeZone with default values #250

Merged
merged 3 commits into from
Apr 21, 2021
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- TZOFFSETTO and TZOFFSETFROM should never be -0000 [#246](https://github.com/markuspoerschke/iCal/pull/246)
- Calling TimeZone::createFromPhpDateTimeZone with default values fails with assertion

### Deprecated

- Method `Eluceo\iCal\Domain\Entity\TimeZone::createFromPhpDateTimeZone` will not have default values
for `$beginDateTime` and `$endDateTime` in the next major version.

## [2.0.0] - 2021-03-29

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"require": {
"php": ">=7.4 || ~8.0.0",
"ext-mbstring": "*"
"ext-mbstring": "*",
"symfony/deprecation-contracts": "^2.1"
},
"conflict": {
"php": "7.4.6"
Expand Down
139 changes: 70 additions & 69 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/Domain/Entity/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public static function createFromPhpDateTimeZone(
?DateTimeInterface $beginDateTime = null,
?DateTimeInterface $endDateTime = null
): self {
if ($beginDateTime === null || $endDateTime === null) {
trigger_deprecation('eluceo/ical', '2.1.0', 'Relying on the default values for begin and end date when calling TimeZone::createFromPhpDateTimeZone() is deprecated. Please provide a begin and an end date.');
}

$transitions = $phpDateTimeZone->getTransitions(
$beginDateTime ? $beginDateTime->getTimestamp() : PHP_INT_MIN,
$beginDateTime ? $beginDateTime->getTimestamp() : (new DateTimeImmutable('0000-01-01 12:00:00'))->getTimestamp(),
$endDateTime ? $endDateTime->getTimestamp() : PHP_INT_MAX
);
$timeZone = new self($phpDateTimeZone->getName());
Expand All @@ -48,7 +52,7 @@ public static function createFromPhpDateTimeZone(
DateTimeImmutable::ISO8601,
$transitionArray['time']
);
assert($fromDateTime instanceof DateTimeImmutable);
assert($fromDateTime instanceof DateTimeImmutable, $transitionArray['time']);
$localFromDateTime = $fromDateTime->setTimezone($phpDateTimeZone);

$timeZone->addTransition(new TimeZoneTransition(
Expand Down