Skip to content

Commit 06d4c70

Browse files
committed
Integrate timelib 2022.02
- Fixed #124: Can't parse INT_MIN - Added a new API, timelib_get_time_zone_offset_info, which reduces allocation speeding up algorithms (Alberto Massari) - Accelerate the do_range_limit_days algorythm by advancing multiple months in a single call (Alberto Massari) Including fixes from 2021.17: - Fixed 'const' and other compiler warnings - Use new 'PACKRAT' format to prevent old timestamps from becoming incorrect - New 2022b data file - Fixed PHP GH-9165: strtotime translates a date-time with DST/non-DST hour differently
1 parent 2480d9c commit 06d4c70

File tree

11 files changed

+336
-230
lines changed

11 files changed

+336
-230
lines changed

ext/date/lib/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ support.
1111
Build Requirements
1212
------------------
1313

14-
On Debian: ``apt install libcpputest-dev``
14+
On Debian: ``apt install libcpputest-dev re2c``

ext/date/lib/interval.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ static void sort_old_to_new(timelib_time **one, timelib_time **two, timelib_rel_
9090
static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time *two)
9191
{
9292
timelib_rel_time *rt;
93-
timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0;
94-
timelib_time_offset *trans = NULL;
93+
timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0;
94+
int32_t trans_offset;
95+
timelib_sll trans_transition_time;
9596

9697
rt = timelib_rel_time_ctor();
9798
rt->invert = 0;
@@ -117,16 +118,16 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
117118
if (one->dst == 1 && two->dst == 0) {
118119
/* First for two "Type 3" times */
119120
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID) {
120-
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
121-
if (trans) {
122-
if (one->sse < trans->transition_time && one->sse >= trans->transition_time + dst_corr) {
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+
) {
123127
timelib_sll flipped = SECS_PER_HOUR + (rt->i * 60) + (rt->s);
124128
rt->h = flipped / SECS_PER_HOUR;
125129
rt->i = (flipped - rt->h * SECS_PER_HOUR) / 60;
126130
rt->s = flipped % 60;
127-
}
128-
timelib_time_offset_dtor(trans);
129-
trans = NULL;
130131
}
131132
} else if (rt->h == 0 && (rt->i < 0 || rt->s < 0)) {
132133
/* Then for all the others */
@@ -145,39 +146,40 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
145146
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID && strcmp(one->tz_info->name, two->tz_info->name) == 0) {
146147
if (one->dst == 1 && two->dst == 0) { /* Fall Back */
147148
if (two->tz_info) {
148-
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
149+
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
149150

150151
if (
151-
trans &&
152-
two->sse >= trans->transition_time &&
153-
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans->transition_time)
152+
success &&
153+
two->sse >= trans_transition_time &&
154+
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans_transition_time)
154155
) {
155156
rt->h -= dst_h_corr;
156157
rt->i -= dst_m_corr;
157158
}
158159
}
159160
} else if (one->dst == 0 && two->dst == 1) { /* Spring Forward */
160161
if (two->tz_info) {
161-
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
162+
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
162163

163164
if (
164-
trans &&
165-
!((one->sse + SECS_PER_DAY > trans->transition_time) && (one->sse + SECS_PER_DAY <= (trans->transition_time + dst_corr))) &&
166-
two->sse >= trans->transition_time &&
167-
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans->transition_time)
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)
168169
) {
169170
rt->h -= dst_h_corr;
170171
rt->i -= dst_m_corr;
171172
}
172173
}
173174
} else if (two->sse - one->sse >= SECS_PER_DAY) {
174175
/* Check whether we're in the period to the next transition time */
175-
trans = timelib_get_time_zone_info(two->sse - two->z, two->tz_info);
176-
dst_corr = one->z - trans->offset;
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;
177178

178-
if (two->sse >= trans->transition_time - dst_corr && two->sse < trans->transition_time) {
179-
rt->d--;
180-
rt->h = 24;
179+
if (two->sse >= trans_transition_time - dst_corr && two->sse < trans_transition_time) {
180+
rt->d--;
181+
rt->h = 24;
182+
}
181183
}
182184
}
183185
} else {
@@ -189,10 +191,6 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
189191
timelib_do_rel_normalize(rt->invert ? one : two, rt);
190192
}
191193

192-
if (trans) {
193-
timelib_time_offset_dtor(trans);
194-
}
195-
196194
return rt;
197195
}
198196

0 commit comments

Comments
 (0)