[wp-trac] [WordPress Trac] #38940: current_time() expects that date_default_timezone_set is never used
WordPress Trac
noreply at wordpress.org
Tue May 2 11:58:24 UTC 2017
#38940: current_time() expects that date_default_timezone_set is never used
------------------------------------------------+--------------------------
Reporter: marco.marsala | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
Component: Date/Time | Review
Severity: normal | Version: 4.6.1
Keywords: has-patch dev-feedback 2nd-opinion | Resolution:
| Focuses:
------------------------------------------------+--------------------------
Comment (by Rarst):
Ticket description gets scope slightly wrong. `current_time()` is not
broken ''if'' PHP timezone is changed, it is just ''broken altogether'' in
context
{{{#!php
<?php
var_dump( date_default_timezone_get() );
// "UTC"
var_dump( date('D, j M Y H:i:s O') );
// "Tue, 2 May 2017 11:38:08 +0000" << correct UTC
var_dump( current_time( 'D, j M Y H:i:s O' ) );
// "Tue, 2 May 2017 14:38:08 +0000" << local time, invalid time zone
var_dump( current_time( 'D, j M Y H:i:s O', true ) );
// "Tue, 2 May 2017 11:38:08 +0000" << correct UTC
}}}
The logic of feeding "WP timestamp" into `date()` is just inherently
broken and cannot produce correct output.
Effectively any format with timezone will produce invalid results, unless
`gmt` flag is set.
I am against the suggested patch, this is not PHP API problem and
shouldn't be approached as one.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38940#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list