Skip to content

Commit

Permalink
Integrate timelib 2022.02
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
derickr committed Sep 14, 2022
1 parent 2480d9c commit 06d4c70
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 230 deletions.
2 changes: 1 addition & 1 deletion ext/date/lib/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ support.
Build Requirements
------------------

On Debian: ``apt install libcpputest-dev``
On Debian: ``apt install libcpputest-dev re2c``
50 changes: 24 additions & 26 deletions ext/date/lib/interval.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ static void sort_old_to_new(timelib_time **one, timelib_time **two, timelib_rel_
static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time *two)
{
timelib_rel_time *rt;
timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0;
timelib_time_offset *trans = NULL;
timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0;
int32_t trans_offset;
timelib_sll trans_transition_time;

rt = timelib_rel_time_ctor();
rt->invert = 0;
Expand All @@ -117,16 +118,16 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
if (one->dst == 1 && two->dst == 0) {
/* First for two "Type 3" times */
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID) {
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
if (trans) {
if (one->sse < trans->transition_time && one->sse >= trans->transition_time + dst_corr) {
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);
if (
success &&
one->sse < trans_transition_time &&
one->sse >= trans_transition_time + dst_corr
) {
timelib_sll flipped = SECS_PER_HOUR + (rt->i * 60) + (rt->s);
rt->h = flipped / SECS_PER_HOUR;
rt->i = (flipped - rt->h * SECS_PER_HOUR) / 60;
rt->s = flipped % 60;
}
timelib_time_offset_dtor(trans);
trans = NULL;
}
} else if (rt->h == 0 && (rt->i < 0 || rt->s < 0)) {
/* Then for all the others */
Expand All @@ -145,39 +146,40 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID && strcmp(one->tz_info->name, two->tz_info->name) == 0) {
if (one->dst == 1 && two->dst == 0) { /* Fall Back */
if (two->tz_info) {
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);

if (
trans &&
two->sse >= trans->transition_time &&
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans->transition_time)
success &&
two->sse >= trans_transition_time &&
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans_transition_time)
) {
rt->h -= dst_h_corr;
rt->i -= dst_m_corr;
}
}
} else if (one->dst == 0 && two->dst == 1) { /* Spring Forward */
if (two->tz_info) {
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
int success = timelib_get_time_zone_offset_info(two->sse, two->tz_info, &trans_offset, &trans_transition_time, NULL);

if (
trans &&
!((one->sse + SECS_PER_DAY > trans->transition_time) && (one->sse + SECS_PER_DAY <= (trans->transition_time + dst_corr))) &&
two->sse >= trans->transition_time &&
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans->transition_time)
success &&
!((one->sse + SECS_PER_DAY > trans_transition_time) && (one->sse + SECS_PER_DAY <= (trans_transition_time + dst_corr))) &&
two->sse >= trans_transition_time &&
((two->sse - one->sse + dst_corr) % SECS_PER_DAY) > (two->sse - trans_transition_time)
) {
rt->h -= dst_h_corr;
rt->i -= dst_m_corr;
}
}
} else if (two->sse - one->sse >= SECS_PER_DAY) {
/* Check whether we're in the period to the next transition time */
trans = timelib_get_time_zone_info(two->sse - two->z, two->tz_info);
dst_corr = one->z - trans->offset;
if (timelib_get_time_zone_offset_info(two->sse - two->z, two->tz_info, &trans_offset, &trans_transition_time, NULL)) {
dst_corr = one->z - trans_offset;

if (two->sse >= trans->transition_time - dst_corr && two->sse < trans->transition_time) {
rt->d--;
rt->h = 24;
if (two->sse >= trans_transition_time - dst_corr && two->sse < trans_transition_time) {
rt->d--;
rt->h = 24;
}
}
}
} else {
Expand All @@ -189,10 +191,6 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
timelib_do_rel_normalize(rt->invert ? one : two, rt);
}

if (trans) {
timelib_time_offset_dtor(trans);
}

return rt;
}

Expand Down
Loading

0 comments on commit 06d4c70

Please sign in to comment.