Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -4458,16 +4458,20 @@ PHP_FUNCTION(timezone_transitions_get)
}
}
if (tzobj->tzi.tz->posix_info && tzobj->tzi.tz->posix_info->dst_end) {
timelib_sll start_y, end_y, dummy_m, dummy_d;
timelib_sll start_y, begin_y, end_y, dummy_m, dummy_d;
timelib_sll last_transition_ts = tzobj->tzi.tz->trans[tzobj->tzi.tz->bit64.timecnt - 1];

/* Find out year for last transition */
timelib_unixtime2date(last_transition_ts, &start_y, &dummy_m, &dummy_d);

/* Find out year for first boundary timestamp */
timelib_unixtime2date(timestamp_begin, &begin_y, &dummy_m, &dummy_d);

/* Find out year for final boundary timestamp */
timelib_unixtime2date(timestamp_end, &end_y, &dummy_m, &dummy_d);

for (timelib_sll i = start_y; i <= end_y; i++) {
/* The previous year's rules can still produce a transition in the range */
for (timelib_sll i = MAX(start_y, begin_y - 1); i <= end_y; i++) {
timelib_posix_transitions transitions = { 0 };

timelib_get_transitions_for_year(tzobj->tzi.tz, i, &transitions);
Expand Down
64 changes: 64 additions & 0 deletions ext/date/tests/DateTimeZone_getTransitions_far_future.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--TEST--
DateTimeZone::getTransitions() with a far-future range
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
--FILE--
<?php
$tz = new DateTimeZone('Europe/Amsterdam');
var_dump(count($tz->getTransitions(PHP_INT_MAX - 1000, PHP_INT_MAX)));

function dump(string $zone, string $begin, string $end): void {
echo "$zone $begin - $end\n";
$tz = new DateTimeZone($zone);
$b = (new DateTimeImmutable($begin, new DateTimeZone('UTC')))->getTimestamp();
$e = (new DateTimeImmutable($end, new DateTimeZone('UTC')))->getTimestamp();
foreach ($tz->getTransitions($b, $e) as $t) {
echo "{$t['ts']} {$t['offset']} ", (int) $t['isdst'], " {$t['abbr']}\n";
}
}

dump('Europe/Amsterdam', '2100-01-01', '2110-01-01');
dump('America/New_York', '2101-01-01', '2103-01-01');
dump('Australia/Sydney', '2101-01-01', '2103-01-01');
dump('Australia/Sydney', '2101-01-02', '2101-12-31');
?>
--EXPECT--
int(1)
Europe/Amsterdam 2100-01-01 - 2110-01-01
4102444800 3600 0 CET
4109878800 7200 1 CEST
4128627600 3600 0 CET
4141328400 7200 1 CEST
4160077200 3600 0 CET
4172778000 7200 1 CEST
4191526800 3600 0 CET
4204227600 7200 1 CEST
4222976400 3600 0 CET
4236282000 7200 1 CEST
4254426000 3600 0 CET
4267731600 7200 1 CEST
4285875600 3600 0 CET
4299181200 7200 1 CEST
4317930000 3600 0 CET
4330630800 7200 1 CEST
4349379600 3600 0 CET
4362080400 7200 1 CEST
4380829200 3600 0 CET
4394134800 7200 1 CEST
4412278800 3600 0 CET
America/New_York 2101-01-01 - 2103-01-01
4133980800 -18000 0 EST
4140140400 -14400 1 EDT
4160700000 -18000 0 EST
4171590000 -14400 1 EDT
4192149600 -18000 0 EST
Australia/Sydney 2101-01-01 - 2103-01-01
4133980800 39600 1 AEDT
4141900800 36000 0 AEST
4157625600 39600 1 AEDT
4173350400 36000 0 AEST
4189075200 39600 1 AEDT
Australia/Sydney 2101-01-02 - 2101-12-31
4134067200 39600 1 AEDT
4141900800 36000 0 AEST
4157625600 39600 1 AEDT
Loading