Closed
Conversation
added 3 commits
November 9, 2021 19:05
…lib sets timestamps bases on UTC local times
… for a timezone east of UTC
Author
|
I actually fixed it I think, I'll make a new PR for that |
| foreach ($timezonesWithTimestamps as $timezone => $timestamps) { | ||
| foreach ($timestamps as $timestamp) { | ||
| $tz = new DateTimeZone($timezone); | ||
| $dt = DateTime::createFromFormat('U', $timestamp); |
Contributor
There was a problem hiding this comment.
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/AmsterdamWhich 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
DateTimeobject representing such a moment to a DST-supporting timezone fails.The
setTimezonebug appears to have already been fixed for PHP 8.1, but not in 7.4The
setTimestampbug appears in all versions I tested (7.1 and up)