-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Add TimezoneChange XML doc (#1731)
* Docs: Add TimezoneChange XML doc
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
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> |