From 68b874d10d9ff2fc0c3915147c286009e2cfbe34 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Tue, 5 Oct 2021 15:22:55 +0100 Subject: [PATCH] Fixed bug #81504: Incorrect timezone transition details for POSIX data --- NEWS | 4 ++++ ext/date/php_date.c | 11 ++++++++++- ext/date/tests/bug81504.phpt | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ext/date/tests/bug81504.phpt diff --git a/NEWS b/NEWS index addc4f66bcd..bce846813df 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ PHP NEWS Doleček) . Fixed bug #81380 (Observer may not be initialized properly). (krakjoe) +- Date: + . Fixed bug #81504 (Incorrect timezone transition details for POSIX data). + (Derick) + - PCRE: . Unfixed bug #81424 (PCRE2 10.35 JIT performance regression). (cmb) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index f11357691e2..e2943e6f708 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3620,6 +3620,15 @@ PHP_FUNCTION(timezone_transitions_get) add_assoc_string(&element, "abbr", &tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].abbr_idx]); \ add_next_index_zval(return_value, &element); +#define add_by_index(i,ts) \ + array_init(&element); \ + add_assoc_long(&element, "ts", ts); \ + add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, ts, 0)); \ + add_assoc_long(&element, "offset", tzobj->tzi.tz->type[i].offset); \ + add_assoc_bool(&element, "isdst", tzobj->tzi.tz->type[i].isdst); \ + add_assoc_string(&element, "abbr", &tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[i].abbr_idx]); \ + add_next_index_zval(return_value, &element); + #define add_last() add(tzobj->tzi.tz->bit64.timecnt - 1, timestamp_begin) array_init(return_value); @@ -3685,7 +3694,7 @@ PHP_FUNCTION(timezone_transitions_get) if (transitions.times[j] > timestamp_end) { return; } - add(transitions.types[j], transitions.times[j]); + add_by_index(transitions.types[j], transitions.times[j]); } } } diff --git a/ext/date/tests/bug81504.phpt b/ext/date/tests/bug81504.phpt new file mode 100644 index 00000000000..c638d647892 --- /dev/null +++ b/ext/date/tests/bug81504.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #81504: Incorrect timezone transition details for POSIX data +--FILE-- +getTransitions(strtotime("1996-01-01"), strtotime("1997-12-31")) as $tr) { + echo "{$tr['time']} {$tr['offset']} {$tr['abbr']}\n"; +} +?> +--EXPECT-- +1996-01-01T00:00:00+0000 3600 CET +1996-03-31T01:00:00+0000 7200 CEST +1996-10-27T01:00:00+0000 3600 CET +1997-03-30T01:00:00+0000 7200 CEST +1997-10-26T01:00:00+0000 3600 CET