From 978281ddcefcb6136c42613b917ebda599db68db Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Thu, 22 Apr 2021 00:16:07 +0200 Subject: [PATCH 1/3] Add unit test for bug #80974 Wrong diff between 2 dates in different timezones --- ext/date/tests/bug80974.phpt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ext/date/tests/bug80974.phpt diff --git a/ext/date/tests/bug80974.phpt b/ext/date/tests/bug80974.phpt new file mode 100644 index 0000000000000..ed2ae9dc3a461 --- /dev/null +++ b/ext/date/tests/bug80974.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #80974 (Wrong diff between 2 dates in different timezones) +--FILE-- +format('%h'), "\n"; +?> +--EXPECT-- +3 From 53627f9d178f8c709b0a181e2f67673b8a0ccefe Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Thu, 22 Apr 2021 12:41:57 +0200 Subject: [PATCH 2/3] Do normalize for zone_type 3 comparison not in special cases --- ext/date/lib/interval.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/date/lib/interval.c b/ext/date/lib/interval.c index 0a6163d0c1d6a..747f49cf661a5 100644 --- a/ext/date/lib/interval.c +++ b/ext/date/lib/interval.c @@ -127,6 +127,12 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two) rt->d--; rt->h = 24; } + } else { + /* Then for all the others */ + rt->h -= dst_h_corr + (two->dst - one->dst); + rt->i -= dst_m_corr; + + timelib_do_rel_normalize(rt->invert ? one : two, rt); } } else { /* Then for all the others */ From 0b07cce28895741dc9cea20759308d95e0f8e990 Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Thu, 22 Apr 2021 13:58:43 +0200 Subject: [PATCH 3/3] Dedupe normalize code --- ext/date/lib/interval.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ext/date/lib/interval.c b/ext/date/lib/interval.c index 747f49cf661a5..16990c55c2117 100644 --- a/ext/date/lib/interval.c +++ b/ext/date/lib/interval.c @@ -32,6 +32,7 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two) timelib_time *swp; timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0; timelib_time_offset *trans = NULL; + bool normalize = 0; rt = timelib_rel_time_ctor(); @@ -128,13 +129,13 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two) rt->h = 24; } } else { - /* Then for all the others */ - rt->h -= dst_h_corr + (two->dst - one->dst); - rt->i -= dst_m_corr; - - timelib_do_rel_normalize(rt->invert ? one : two, rt); + normalize = 1; } } else { + normalize = 1; + } + + if (normalize) { /* Then for all the others */ rt->h -= dst_h_corr + (two->dst - one->dst); rt->i -= dst_m_corr;