Skip to content

Commit

Permalink
Docs: Refresh restricted datetime functions docs
Browse files Browse the repository at this point in the history
Kept the descriptions for individual code comparisons simpler, and populated the <standard> element with more description instead.
  • Loading branch information
GaryJones committed Mar 28, 2022
1 parent 415cccf commit d074fc8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
44 changes: 44 additions & 0 deletions WordPress/Docs/DateTime/RestrictedFunctionsStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<documentation title="Restricted Date and Time Functions">
<standard>
<![CDATA[
The restricted functions date_default_timezone_set() and date() should not be used.
Using date_default_timezone_set() isn't allowed, because WordPress core needs default time zone set to UTC. Use DateTime object or WP core API functions instead.
Using date() isn't allowed, as it is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
]]>
</standard>
<code_comparison>
<code title="Valid: Using DateTime object.">
<![CDATA[
$date = new DateTime();
$date->setTimezone(
new DateTimeZone( 'Europe/Amsterdam' )
);
]]>
</code>
<code title="Invalid: Using date_default_timezone_set().">
<![CDATA[
date_default_timezone_set( 'Europe/Amsterdam' );
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: Using gmdate().">
<![CDATA[
$last_updated = gmdate(
'Y-m-d\TH:i:s',
strtotime( $plugin['last_updated'] )
);
]]>
</code>
<code title="Invalid: Using date().">
<![CDATA[
$last_updated = date(
'Y-m-d\TH:i:s',
strtotime( $plugin['last_updated'] )
);
]]>
</code>
</code_comparison>
</documentation>
22 changes: 0 additions & 22 deletions WordPress/Docs/WP/TimezoneChangeStandard.xml

This file was deleted.

0 comments on commit d074fc8

Please sign in to comment.