[wp-trac] [WordPress Trac] #53780: PHP 8.1: DateTimeZone::getTransitions() change
WordPress Trac
noreply at wordpress.org
Thu Feb 6 17:59:28 UTC 2025
#53780: PHP 8.1: DateTimeZone::getTransitions() change
--------------------------+------------------------------
Reporter: autotutorial | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version:
Severity: normal | Resolution:
Keywords: php81 close | Focuses:
--------------------------+------------------------------
Comment (by autotutorial):
Good evening everyone, I thought there was a probable solution but I'll
explain bug 7752 which was resolved by php 8.1.6RC. Here is a non-
exhaustive list of things that happen https://github.com/php/php-
src/issues/7752#issuecomment-1085765090
In this code example I use if I have a single result and the last
transition is less than or equal to the timestamp and 7200 is equal to
that offset means from bug 8.1 :)
{{{
<?php
$tz_string = 'Europe/Paris';
$timezone_utc = timezone_open('UTC');
$timezone = timezone_open($tz_string);
//$lasttimestamp = 4141328400;
$lasttimestamp = 4160077200;
$lasttimestamp2 = '' . $lasttimestamp;
$to_min = strtr($lasttimestamp2, array('-2147483648' => '-2147483647',
'-2147483647' => '-2147483647', '2147483647' => '2147483646'));
$to_min = (int) $to_min;
$to_min = '' . $to_min;
$to_min = strtr($to_min, array('-2147483648' => '2147483647'));
$to_min = (int) $to_min;
$from_max = 2147483647;
$to_min2 = 2147483647;
if($to_min > 2147483647 || -2147483648 > $to_min) {
$from_max = '2147483648';
$from_max = (int) $from_max;
} elseif($to_min < 2147483647) {
$to_min2 = 2147483646;
}
if($from_max > $to_min2) {
$lasttimestamp = (int) $lasttimestamp;
$timestampsec = '+0 sec';
$date1 = date_create('1970-01-01 00:00:00', $timezone_utc);
$date2 = date_modify($date1, $timestampsec);
$obj_rt = is_object($date2);
$key3 = 1;
$key4 = 1;
if($obj_rt) {
$transitions = timezone_transitions_get($timezone, $lasttimestamp);
$count = count($transitions);
if(2 > $count) {
$transitions2 = timezone_transitions_get($timezone);
$key2 = count($transitions2) - 1;
$lasttimestamp2 = $transitions2[$key2]['ts'];
$check = $lasttimestamp2 <= $lasttimestamp;
if($check) {
$lasttimestamp2 = 4160077200;
$timezone_test = timezone_open('Europe/Paris');
$transitions3 = timezone_transitions_get($timezone_test, $lasttimestamp2);
$offset1 = $transitions3[0]['offset'];
if(7200 == $offset1) {
$key3 = $key2 - 1;
$key4 = 0;
if($key2 > 0) {
$key4 = 1;
} else {
$key3 = 0;
}
$arr = explode('T', $transitions[0]['time']);
$copy = $arr[0];
$arr = explode('+', $arr[1]);
$string = '+' . $copy . ' ' . $arr[0];
$date2 = null;
$date1 = null;
unset($date2);
unset($date1);
$string = strtr($string, array('+-' => '-'));
$date1 = date_create($string, $timezone_utc);
$offset1 = $transitions[0]['offset'];
$timestampsec = '+';
if(0 > $offset1) {
$timestampsec = '';
}
$timestampsec = $timestampsec . $offset1 . ' sec';
$date2 = date_modify($date1, $timestampsec);
$string = date_format($date2, 'Y-m-d H:i:s');
$date2 = null;
$date1 = null;
unset($date2);
unset($date1);
$date1 = date_create($string, $timezone);
$offset2 = date_format($date1, 'Z');
$offset2 = (int) $offset2;
if($offset1 != $offset2) {
$key4 = $key3;
$offset3 = $transitions2[$key2]['offset'];
if($offset2 == $offset3) {
$key4 = $key2;
}
$transitions[0]['offset'] = $transitions2[$key4]['offset'];
$transitions[0]['isdst'] = $transitions2[$key4]['isdst'];
$transitions[0]['abbr'] = $transitions2[$key4]['abbr'];
}
}
}
$key3 = 0;
$key4 = 0;
} elseif($transitions[0]['ts'] == $transitions[1]['ts']) {
unset($transitions[1]);
if(3 > $count) {
$key3 = 0;
$key4 = 0;
} else {
$key3 = 2;
}
}
$transitiontimestamp = array($transitions[0], $key4 =>
$transitions[$key3]);
} else {
//
//$transitions2 = timezone_transitions_get($timezone);
}
}
var_dump($transitiontimestamp[0]);
?>
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53780#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list