-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Docs: Add TimezoneChange XML doc #1731
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<documentation title="Restricted Date and Time Functions"> | ||
<standard> | ||
<![CDATA[ | ||
The restricted functions date_default_timezone_set() and date() should not be used. | ||
]]> | ||
</standard> | ||
<standard> | ||
<![CDATA[ | ||
Using the PHP native date_default_timezone_set() function isn't allowed, because WordPress Core needs the default time zone to be set to UTC for timezone calculations using the WP Core API to work correctly. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Using DateTime object."> | ||
<![CDATA[ | ||
$date = new <em>DateTime()</em>; | ||
$date->setTimezone( | ||
new DateTimeZone( 'Europe/Amsterdam' ) | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Using date_default_timezone_set()."> | ||
<![CDATA[ | ||
<em>date_default_timezone_set</em>( 'Europe/Amsterdam' ); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<standard> | ||
<![CDATA[ | ||
Using the PHP native date() function isn't allowed, as it is affected by runtime timezone changes which can cause the date/time to be incorrectly displayed. Use gmdate() instead. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Using gmdate()."> | ||
<![CDATA[ | ||
$last_updated = <em>gmdate</em>( | ||
'Y-m-d\TH:i:s', | ||
strtotime( $plugin['last_updated'] ) | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Using date()."> | ||
<![CDATA[ | ||
$last_updated = <em>date</em>( | ||
'Y-m-d\TH:i:s', | ||
strtotime( $plugin['last_updated'] ) | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
</documentation> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be an idea to "WordPressify" this code sample a little more and use something like
get_option()
withgmt_offset
ortimezone_string
to retrieve the timezone to be passed tonew DateTimeZone()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the basic PHP example is fine there, people tend to change default time zone to something that is not normal WP time zone.
Again, there is a problem of choice between a technical 1:1 code equivalent and idiomatic rewrite, that is hard to decide on for brief out-of-context example.