Skip to content

Commit

Permalink
Docs: Add TimezoneChange XML doc (#1731)
Browse files Browse the repository at this point in the history
* Docs: Add TimezoneChange XML doc
  • Loading branch information
GaryJones committed Jun 4, 2022
1 parent cfdb6d1 commit 750cb11
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions WordPress/Docs/DateTime/RestrictedFunctionsStandard.xml
@@ -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>

0 comments on commit 750cb11

Please sign in to comment.