[wp-trac] [WordPress Trac] #38940: current_time() expects that date_default_timezone_set is never used

WordPress Trac noreply at wordpress.org
Fri Nov 25 09:28:52 UTC 2016


#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 Review
Component:  Date/Time      |     Version:  4.6.1
 Severity:  normal         |  Resolution:
 Keywords:  has-patch      |     Focuses:
---------------------------+------------------------------
Changes (by marco.marsala):

 * keywords:   => has-patch


Comment:

 A possible code fix would be:

 {{{#!php
 <?php
 function current_time( $type, $gmt = 0 ) {
         $oldgmt = date_default_timezone_get();
         date_default_timezone_set('UTC');
         switch ( $type ) {
                 case 'mysql':
                         return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) :
 gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) *
 HOUR_IN_SECONDS ) ) );
                 case 'timestamp':
                         return ( $gmt ) ? time() : time() + ( get_option(
 'gmt_offset' ) * HOUR_IN_SECONDS );
                 default:
                         return ( $gmt ) ? date( $type ) : date( $type,
 time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
         }
         date_default_timezone_set($oldgmt);
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38940#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list