WordPress.org

Make WordPress Core

Changeset 47073


Ignore:
Timestamp:
01/16/2020 12:26:08 AM (14 months ago)
Author:
SergeyBiryukov
Message:

Date/Time: Use wp_date() to display the correct time of the next DST transition in Timezone setting on General Settings screen.

Props Rarst, autotutorial.
Fixes #49038.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-general.php

    r45932 r47073  
    277277    <br />
    278278    <?php
    279     $allowed_zones = timezone_identifiers_list();
    280 
    281     if ( in_array( $tzstring, $allowed_zones ) ) {
    282         $found                   = false;
    283         $date_time_zone_selected = new DateTimeZone( $tzstring );
    284         $tz_offset               = timezone_offset_get( $date_time_zone_selected, date_create() );
    285         $right_now               = time();
    286         foreach ( timezone_transitions_get( $date_time_zone_selected ) as $tr ) {
    287             if ( $tr['ts'] > $right_now ) {
    288                 $found = true;
    289                 break;
    290             }
    291         }
    292 
    293         if ( $found ) {
     279    if ( in_array( $tzstring, timezone_identifiers_list() ) ) {
     280        $transitions = timezone_transitions_get( timezone_open( $tzstring ), time() );
     281
     282        // 0 index is the state at current time, 1 index is the next transition, if any.
     283        if ( ! empty( $transitions[1] ) ) {
    294284            echo ' ';
    295             $message = $tr['isdst'] ?
     285            $message = $transitions[1]['isdst'] ?
    296286                /* translators: %s: Date and time. */
    297287                __( 'Daylight saving time begins on: %s.' ) :
    298288                /* translators: %s: Date and time. */
    299289                __( 'Standard time begins on: %s.' );
    300             // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
    301290            printf(
    302291                $message,
    303                 '<code>' . date_i18n(
    304                     __( 'F j, Y' ) . ' ' . __( 'g:i a' ),
    305                     $tr['ts'] + ( $tz_offset - $tr['offset'] )
    306                 ) . '</code>'
     292                '<code>' . wp_date( __( 'F j, Y' ) . ' ' . __( 'g:i a' ), $transitions[1]['ts'] ) . '</code>'
    307293            );
    308294        } else {
Note: See TracChangeset for help on using the changeset viewer.