Make WordPress Core

Ticket #37465: wp_timezone_choice.patch

File wp_timezone_choice.patch, 3.6 KB (added by pbearne, 9 years ago)

patch

  • src/wp-includes/functions.php

     
    45334548        $structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __('UTC') . '</option>';
    45344549        $structure[] = '</optgroup>';
    45354550
    4536         // Do manual UTC offsets
    4537         $structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';
    4538         $offset_range = array (-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5,
    4539                 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
    4540         foreach ( $offset_range as $offset ) {
    4541                 if ( 0 <= $offset )
    4542                         $offset_name = '+' . $offset;
    4543                 else
    4544                         $offset_name = (string) $offset;
     4551        if( true === apply_filters( 'show_utc_offsets', empty( get_option('timezone_string') ) ) ) {
     4552                // Do manual UTC offsets
     4553                $structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';
     4554                $offset_range = array (-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5,
     4555                        0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
     4556                foreach ( $offset_range as $offset ) {
     4557                        if ( 0 <= $offset )
     4558                                $offset_name = '+' . $offset;
     4559                        else
     4560                                $offset_name = (string) $offset;
    45454561
    4546                 $offset_value = $offset_name;
    4547                 $offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);
    4548                 $offset_name = 'UTC' . $offset_name;
    4549                 $offset_value = 'UTC' . $offset_value;
    4550                 $selected = '';
    4551                 if ( $offset_value === $selected_zone )
    4552                         $selected = 'selected="selected" ';
    4553                 $structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";
     4562                        $offset_value = $offset_name;
     4563                        $offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);
     4564                        $offset_name = 'UTC' . $offset_name;
     4565                        $offset_value = 'UTC' . $offset_value;
     4566                        $selected = '';
     4567                        if ( $offset_value === $selected_zone )
     4568                                $selected = 'selected="selected" ';
    45544569
     4570                        $structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";
     4571                }
     4572                $structure[] = '</optgroup>';
    45554573        }
    4556         $structure[] = '</optgroup>';
    45574574
    45584575        return join( "\n", $structure );
    45594576}
  • tests/phpunit/tests/functions/wp-timezone-choice.php

     
     1<?php
     2/**
     3 * Tests for size_format()
     4 *
     5 * @group functions.php
     6 * @ticket 36635
     7 */
     8
     9if ( ! defined( 'WPINC' ) ) {
     10        die;
     11}
     12
     13class Test_Functions_WP_Timezone_Choice extends WP_UnitTestCase {
     14
     15        public function _data_Timezone() {
     16                return array(
     17                        array( 'UTC+3', '/.*UTC\+3.*/s' ),
     18                        array( 'UTC-8', '/.*UTC-8.*/s' ),
     19                        array( 'UTC', '/.*UTC.*/s' ),
     20                        array( 'Pacific/Fakaofo', '/.*Pacific\/Fakaofo.*/s' ),
     21                        array( 'America/Toronto"', '/.*America\/Toronto.*/s' ),
     22                );
     23        }
     24
     25        /**
     26         * @dataProvider _data_Timezone
     27         *
     28         * @param $time_zone_string
     29         * @param $expected_in_return
     30         */
     31        public function test_wp_timezone_choice( $time_zone_string, $expected_in_return ) {
     32
     33                $this->assertRegExp( $expected_in_return, wp_timezone_choice( $time_zone_string ) );
     34        }
     35}
     36 No newline at end of file