[wp-trac] [WordPress Trac] #24730: Introduce a timezone-retrieval method

WordPress Trac noreply at wordpress.org
Fri Jun 22 12:33:25 UTC 2018


#24730: Introduce a timezone-retrieval method
-------------------------+------------------------------
 Reporter:  rmccue       |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Date/Time    |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------

Comment (by remcotolsma):

 Maybe a solution to support PHP > 5.2 < 5.5.10:

 {{{#!php
 <?php

 function wp_get_timezone() {
         $timezone_string = get_option( 'timezone_string' );

         if ( ! empty( $timezone_string ) ) {
                 return new DateTimeZone( $timezone_string );
         }

         $gmt_offset = get_option( 'gmt_offset' );
         $hours      = (int) $gmt_offset;
         $minutes    = abs( ( $gmt_offset - (int) $gmt_offset ) * 60 );
         $offset     = sprintf( '%+03d:%02d', $hours, $minutes );

         if ( version_compare( PHP_VERSION, '5.5.10', '<' ) ) {
                 $date = new DateTime( $offset );

                 return $date->getTimezone();
         }

         return new DateTimeZone( $offset );
 }

 }}}

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


More information about the wp-trac mailing list