Make WordPress Core

Changeset 59959


Ignore:
Timestamp:
03/10/2025 02:57:21 PM (7 weeks ago)
Author:
johnbillion
Message:

Date/Time: Fix the recently introduced test for wp_timezone_override_offset() which failed to take into consideration daylight saving time for the America/St_Johns timezone.

Props debarghyabanerjee, johnbillion, mukesh27, audrasjb.

Fixes #63079

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/wpTimezoneOverrideOffset.php

    r59936 r59959  
    3434            'UTC option set'                => array( 'UTC', 0.0 ),
    3535            'EST option set'                => array( 'EST', -5.0 ),
    36             'NST option set'                => array( 'America/St_Johns', -3.5 ),
     36            'NST option set'                => array( 'America/St_Johns', $this->is_timezone_in_dst( 'America/St_Johns' ) ? -2.5 : -3.5 ),
    3737        );
    3838    }
     39
     40    /**
     41     * Determines whether the current timezone offset is observing daylight saving time (DST).
     42     *
     43     * @param string $timezone_string The timezone identifier (e.g., 'America/St_Johns').
     44     * @return bool Whether the timezone is observing DST.
     45     */
     46    private function is_timezone_in_dst( $timezone_string ) {
     47        $timezone    = new DateTimeZone( $timezone_string );
     48        $timestamp   = time();
     49        $transitions = $timezone->getTransitions( $timestamp, $timestamp );
     50
     51        if ( false === $transitions || ! is_array( $transitions ) || ! isset( $transitions[0]['isdst'] ) ) {
     52            return false;
     53        }
     54
     55        return $transitions[0]['isdst'];
     56    }
    3957}
Note: See TracChangeset for help on using the changeset viewer.