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

added unittests for bug #68549 #7636

Closed
wants to merge 4 commits into from
Closed

Conversation

ComaVN
Copy link

@ComaVN ComaVN commented Nov 9, 2021

https://bugs.php.net/bug.php?id=68549

Setting a DateTime's unix timestamp to a moment during around the transition from DST back to standard time fails in some cases.

Likewise, setting the timezone of a DateTime object representing such a moment to a DST-supporting timezone fails.

The setTimezone bug appears to have already been fixed for PHP 8.1, but not in 7.4

The setTimestamp bug appears in all versions I tested (7.1 and up)

@ComaVN ComaVN changed the base branch from master to PHP-7.4 November 9, 2021 13:29
@ComaVN
Copy link
Author

ComaVN commented Nov 10, 2021

I actually fixed it I think, I'll make a new PR for that

@ComaVN ComaVN closed this Nov 10, 2021
foreach ($timezonesWithTimestamps as $timezone => $timestamps) {
foreach ($timestamps as $timestamp) {
$tz = new DateTimeZone($timezone);
$dt = DateTime::createFromFormat('U', $timestamp);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather get to the point where we can call this:

$tz = new DateTimeZone($timezone);
$dt = new DateTimeImmutable('@' . $timestamp, $tz);
printf("%s %d -> %d %s\n", $timezone, $timestamp, $dt->getTimestamp(), $dt->format(DateTimeInterface::ISO8601));

which would internally create the DateTimeImmutable-Object with the timestamp and set the timezone afterwards.

But more interesting would be something like the following:

$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTimeImmutable('2021-10-31T02:30:00+02:00', $tz);
echo $dt->format(DateTimeInterface::ISO8601);
// Sun Oct 31 02:30:00 CEST 2021
echo $dt->getTimezone()->getName();
// Europe/Amsterdam
$dt = new DateTimeImmutable('2021-10-31T02:30:00+01:00', $tz);
echo $dt->format(DateTimeInterface::ISO8601);
// Sun Oct 31 02:30:00 CET 2021
echo $dt->getTimezone()->getName();
// Europe/Amsterdam

Which would require a BC-break as it suddenly uses the second parameter in the constructor that previously was ignored when a Timezoneinformation was given in the timestring (and a timestamp implicitly has a timezone information)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants