Repository navigation
Conversation
Both methods always return an object whose timezone is the UTC offset
+00:00, like new DateTime('@' . $timestamp), whatever the default
timezone is (php_date_initialize_from_ts_long() sets
TIMELIB_ZONETYPE_OFFSET with no offset). This surprises users who
expect the default timezone, as with the constructor and most other
ways to create a date, and the pages did not mention it.
Say so in the description of both pages and add an example that
converts the result to the default timezone with setTimezone(). The
example was run on PHP 8.4 and prints the output shown.
Fixes php#5651
lacatoire
approved these changes
Nov 13, 2026
lacatoire
left a comment
Member
There was a problem hiding this comment.
Thanks for documenting the UTC timezone of createFromTimestamp()!
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.
DateTime::createFromTimestamp()andDateTimeImmutable::createFromTimestamp()always return an object with the UTC offset+00:00as its timezone, the same asnew DateTime('@' . $timestamp). The default timezone is never used:php_date_initialize_from_ts_long()setsTIMELIB_ZONETYPE_OFFSETwith no offset. Most other ways of creating a date use the default timezone, and the pages didn't mention this, so the result looked wrong, as reported in the issue.This adds to both pages:
+00:00, that the default timezone fromdate_default_timezone_get()is not used, and thatsetTimezone()converts the result;DateTimeversion callssetTimezone()in place, and theDateTimeImmutableversion assigns the returned object.I ran both examples on PHP 8.4 and they print the output shown.
configure.phpvalidates and docbook-cs reports no violations.Fixes #5651