[wp-trac] [WordPress Trac] #44985: timezone_string should be valid when offset time zone mode is used

WordPress Trac noreply at wordpress.org
Fri Mar 8 12:24:42 UTC 2019


#44985: timezone_string should be valid when offset time zone mode is used
------------------------------------------+------------------------------
 Reporter:  Rarst                         |       Owner:  (none)
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:  Awaiting Review
Component:  Date/Time                     |     Version:
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:
------------------------------------------+------------------------------

Comment (by nielsdeblaauw):

 I've implemented a naive implementation for this, but ran into some
 warnings that use the timezone_string and can't handle the +HH:MM format.

 {{{Notice: date_default_timezone_set(): Timezone ID '+02:00' is invalid in
 /srv/www/wordpress-trunk/public_html/build/wp-admin/options-general.php on
 line 264}}}

 My incomplete implementation was:

 {{{
 add_filter( 'option_timezone_string', 'wp_timezone_override_string' );
 }}}
 {{{
 function wp_timezone_override_string($string_offset) {
         if(!empty($string_offset)){
                 return $string_offset;
         }
         remove_filter( 'pre_option_gmt_offset',
 'wp_timezone_override_offset' );
         if ( ! $gmt_offset = get_option( 'gmt_offset' ) ) {
                 return $string_offset;
         }
         $offset = gmdate('H:i', floor(abs($gmt_offset) *
 HOUR_IN_SECONDS));
         $prefix = '+';
         if($gmt_offset < 0){
                 $prefix = '-';
         }
         return $prefix . $offset;
 }
 }}}

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


More information about the wp-trac mailing list