Skip to content

Commit 360e6f8

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 71a1e30 + 1dcab8a commit 360e6f8

File tree

4 files changed

+40
-93
lines changed

4 files changed

+40
-93
lines changed

ext/date/lib/interval.c

+34-85
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,6 @@ static void swap_times(timelib_time **one, timelib_time **two, timelib_rel_time
3636
rt->invert = 1;
3737
}
3838

39-
static void swap_if_negative(timelib_rel_time *rt)
40-
{
41-
if (rt->y == 0 && rt->m == 0 && rt->d == 0 && rt->h == 0 && rt->i == 0 && rt->s == 0 && rt->us == 0) {
42-
return;
43-
}
44-
if (rt->y >= 0 && rt->m >= 0 && rt->d >= 0 && rt->h >= 0 && rt->i >= 0 && rt->s >= 0 && rt->us >= 0) {
45-
return;
46-
}
47-
48-
rt->invert = 1 - rt->invert;
49-
rt->y = 0 - rt->y;
50-
rt->m = 0 - rt->m;
51-
rt->d = 0 - rt->d;
52-
rt->h = 0 - rt->h;
53-
rt->i = 0 - rt->i;
54-
rt->s = 0 - rt->s;
55-
rt->us = 0 - rt->us;
56-
}
57-
5839
static void sort_old_to_new(timelib_time **one, timelib_time **two, timelib_rel_time *rt)
5940
{
6041
/* Check whether date/times need to be inverted. If both times are
@@ -115,80 +96,48 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
11596
rt->days = timelib_diff_days(one, two);
11697

11798
/* Fall Back: Cater for transition period, where rt->invert is 0, but there are negative numbers */
118-
if (one->dst == 1 && two->dst == 0) {
119-
/* First for two "Type 3" times */
120-
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID) {
121-
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
122-
if (
123-
success &&
124-
one->sse < trans_transition_time &&
125-
one->sse >= trans_transition_time + dst_corr
126-
) {
127-
timelib_sll flipped = SECS_PER_HOUR + (rt->i * 60) + (rt->s);
128-
rt->h = flipped / SECS_PER_HOUR;
129-
rt->i = (flipped - rt->h * SECS_PER_HOUR) / 60;
130-
rt->s = flipped % 60;
131-
}
132-
} else if (rt->h == 0 && (rt->i < 0 || rt->s < 0)) {
133-
/* Then for all the others */
134-
timelib_sll flipped = SECS_PER_HOUR + (rt->i * 60) + (rt->s);
135-
rt->h = flipped / SECS_PER_HOUR;
136-
rt->i = (flipped - rt->h * SECS_PER_HOUR) / 60;
137-
rt->s = flipped % 60;
138-
dst_corr += SECS_PER_HOUR;
139-
dst_h_corr++;
140-
}
99+
if (two->sse < one->sse) {
100+
timelib_sll flipped = llabs((rt->i * 60) + (rt->s) - dst_corr);
101+
rt->h = flipped / SECS_PER_HOUR;
102+
rt->i = (flipped - rt->h * SECS_PER_HOUR) / 60;
103+
rt->s = flipped % 60;
104+
105+
rt->invert = 1 - rt->invert;
141106
}
142107

143108
timelib_do_rel_normalize(rt->invert ? one : two, rt);
144109

145-
/* Do corrections for "Type 3" times with the same TZID */
146-
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID && strcmp(one->tz_info->name, two->tz_info->name) == 0) {
147-
if (one->dst == 1 && two->dst == 0) { /* Fall Back */
148-
if (two->tz_info) {
149-
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
150-
151-
if (
152-
success &&
153-
two->sse >= trans_transition_time &&
154-
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans_transition_time)
155-
) {
156-
rt->h -= dst_h_corr;
157-
rt->i -= dst_m_corr;
158-
}
110+
if (one->dst == 1 && two->dst == 0) { /* Fall Back */
111+
if (two->tz_info) {
112+
if ((two->sse - one->sse + dst_corr) < SECS_PER_DAY) {
113+
rt->h -= dst_h_corr;
114+
rt->i -= dst_m_corr;
159115
}
160-
} else if (one->dst == 0 && two->dst == 1) { /* Spring Forward */
161-
if (two->tz_info) {
162-
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
163-
164-
if (
165-
success &&
166-
!((one->sse + SECS_PER_DAY > trans_transition_time) && (one->sse + SECS_PER_DAY <= (trans_transition_time + dst_corr))) &&
167-
two->sse >= trans_transition_time &&
168-
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans_transition_time)
169-
) {
170-
rt->h -= dst_h_corr;
171-
rt->i -= dst_m_corr;
172-
}
116+
}
117+
} else if (one->dst == 0 && two->dst == 1) { /* Spring Forward */
118+
if (two->tz_info) {
119+
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
120+
121+
if (
122+
success &&
123+
!((one->sse + SECS_PER_DAY > trans_transition_time) && (one->sse + SECS_PER_DAY <= (trans_transition_time + dst_corr))) &&
124+
two->sse >= trans_transition_time &&
125+
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans_transition_time)
126+
) {
127+
rt->h -= dst_h_corr;
128+
rt->i -= dst_m_corr;
173129
}
174-
} else if (two->sse - one->sse >= SECS_PER_DAY) {
175-
/* Check whether we're in the period to the next transition time */
176-
if (timelib_get_time_zone_offset_info(two->sse - two->z, two->tz_info, &trans_offset, &trans_transition_time, NULL)) {
177-
dst_corr = one->z - trans_offset;
178-
179-
if (two->sse >= trans_transition_time - dst_corr && two->sse < trans_transition_time) {
180-
rt->d--;
181-
rt->h = 24;
182-
}
130+
}
131+
} else if (two->sse - one->sse >= SECS_PER_DAY) {
132+
/* Check whether we're in the period to the next transition time */
133+
if (timelib_get_time_zone_offset_info(two->sse - two->z, two->tz_info, &trans_offset, &trans_transition_time, NULL)) {
134+
dst_corr = one->z - trans_offset;
135+
136+
if (two->sse >= trans_transition_time - dst_corr && two->sse < trans_transition_time) {
137+
rt->d--;
138+
rt->h = 24;
183139
}
184140
}
185-
} else {
186-
rt->h -= dst_h_corr;
187-
rt->i -= dst_m_corr;
188-
189-
swap_if_negative(rt);
190-
191-
timelib_do_rel_normalize(rt->invert ? one : two, rt);
192141
}
193142

194143
return rt;

ext/date/lib/timelib.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
# include "timelib_config.h"
3131
#endif
3232

33-
#define TIMELIB_VERSION 202205
34-
#define TIMELIB_EXTENDED_VERSION 20220501
35-
#define TIMELIB_ASCII_VERSION "2022.05"
33+
#define TIMELIB_VERSION 202206
34+
#define TIMELIB_EXTENDED_VERSION 20220601
35+
#define TIMELIB_ASCII_VERSION "2022.06"
3636

3737
#include <stdlib.h>
3838
#include <stdbool.h>

ext/date/tests/DateTime_diff-fall-type3-type3.phpt

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
DateTime::diff() -- fall type3 type3
33
--CREDITS--
44
Daniel Convissor <danielc@php.net>
5-
--XFAIL--
6-
Various bugs exist
75
--FILE--
86
<?php
97

@@ -30,7 +28,7 @@ test_time_fall_type3_redodt_type3_dt: DIFF: 2010-11-07 00:10:20 EDT - 2010-11-07
3028
test_time_fall_type3_redodt_type3_redodt: DIFF: 2010-11-07 01:15:35 EDT - 2010-11-07 01:12:33 EDT = **P+0Y0M0DT0H3M2S**
3129
test_time_fall_type3_redodt_type3_redost: DIFF: 2010-11-07 01:14:44 EST - 2010-11-07 01:12:33 EDT = **P+0Y0M0DT1H2M11S**
3230
test_time_fall_type3_redodt_type3_st: DIFF: 2010-11-07 03:16:55 EST - 2010-11-07 01:12:33 EDT = **P+0Y0M0DT3H4M22S**
33-
test_time_fall_type3_redodt_type3_post: DIFF: 2010-11-08 19:59:59 EST - 2010-11-07 01:12:33 EDT = **P+0Y0M1DT19H47M26S**
31+
test_time_fall_type3_redodt_type3_post: DIFF: 2010-11-08 19:59:59 EST - 2010-11-07 01:12:33 EDT = **P+0Y0M1DT18H47M26S**
3432
test_time_fall_type3_redost_type3_prev: DIFF: 2010-11-06 18:38:28 EDT - 2010-11-07 01:14:44 EST = **P-0Y0M0DT7H36M16S**
3533
test_time_fall_type3_redost_type3_dt: DIFF: 2010-11-07 00:10:20 EDT - 2010-11-07 01:14:44 EST = **P-0Y0M0DT2H4M24S**
3634
test_time_fall_type3_redost_type3_redodt: DIFF: 2010-11-07 01:12:33 EDT - 2010-11-07 01:14:44 EST = **P-0Y0M0DT1H2M11S**
@@ -45,7 +43,7 @@ test_time_fall_type3_st_type3_st: DIFF: 2010-11-07 05:19:56 EST - 2010-11-07 03:
4543
test_time_fall_type3_st_type3_post: DIFF: 2010-11-08 19:59:59 EST - 2010-11-07 03:16:55 EST = **P+0Y0M1DT16H43M4S**
4644
test_time_fall_type3_post_type3_prev: DIFF: 2010-11-06 18:38:28 EDT - 2010-11-08 19:59:59 EST = **P-0Y0M2DT1H21M31S**
4745
test_time_fall_type3_post_type3_dt: DIFF: 2010-11-07 00:10:20 EDT - 2010-11-08 19:59:59 EST = **P-0Y0M1DT19H49M39S**
48-
test_time_fall_type3_post_type3_redodt: DIFF: 2010-11-07 01:12:33 EDT - 2010-11-08 19:59:59 EST = **P-0Y0M1DT19H47M26S**
46+
test_time_fall_type3_post_type3_redodt: DIFF: 2010-11-07 01:12:33 EDT - 2010-11-08 19:59:59 EST = **P-0Y0M1DT18H47M26S**
4947
test_time_fall_type3_post_type3_redost: DIFF: 2010-11-07 01:14:44 EST - 2010-11-08 19:59:59 EST = **P-0Y0M1DT18H45M15S**
5048
test_time_fall_type3_post_type3_st: DIFF: 2010-11-07 03:16:55 EST - 2010-11-08 19:59:59 EST = **P-0Y0M1DT16H43M4S**
5149
test_time_fall_type3_post_type3_post: DIFF: 2010-11-08 19:59:59 EST - 2010-11-08 18:57:55 EST = **P+0Y0M0DT1H2M4S**

ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-bd2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ echo 'bd8b ' . $end->format($date_format) . ' - ' . $start->format($date_format)
5454
echo "\n";
5555
?>
5656
--EXPECT--
57-
bd0 2010-11-07 01:00:00 EST America/New_York - 2010-11-07 01:59:59 EDT America/New_York = P0DT0H59M59S
57+
bd0 2010-11-07 01:00:00 EST America/New_York - 2010-11-07 01:59:59 EDT America/New_York = P0DT0H0M1S
5858
bd5 2010-11-07 01:30:00 EST America/New_York - 2010-11-06 04:30:00 EDT America/New_York = P0DT22H
5959
bd6 2010-11-07 01:30:00 EDT America/New_York - 2010-11-06 04:30:00 EDT America/New_York = P0DT21H
6060
bd8a 2010-11-07 01:00:00 EST America/New_York - 2010-11-06 01:00:00 EDT America/New_York = P1DT0H

0 commit comments

Comments
 (0)