Skip to content

Commit

Permalink
Upgrade timelib to 2021.08, which address some defects and performance
Browse files Browse the repository at this point in the history
- Fixed bug #80998 (Missing second with inverted interval).
- Speed up finding timezone offset information.
  • Loading branch information
derickr committed Aug 31, 2021
1 parent 14f599e commit 2bf451b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ PHP NEWS
. Dispatch using LANG_NEUTRAL instead of LOCALE_SYSTEM_DEFAULT. (Dmitry
Maksimov)

- Date:
. Fixed bug #80998 (Missing second with inverted interval). (Derick)
. Speed up finding timezone offset information. (Derick)

19 Aug 2021, PHP 8.1.0beta3

- Core:
Expand Down
11 changes: 10 additions & 1 deletion ext/date/lib/interval.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ timelib_time *timelib_add_wall(timelib_time *old_time, timelib_rel_time *interva
memcpy(&t->relative, interval, sizeof(timelib_rel_time));

timelib_update_ts(t, NULL);

timelib_update_from_sse(t);
} else {
if (interval->invert) {
bias = -1;
Expand All @@ -247,11 +249,14 @@ timelib_time *timelib_add_wall(timelib_time *old_time, timelib_rel_time *interva

do_range_limit(0, 1000000, 1000000, &interval->us, &interval->s);
t->sse += bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
timelib_update_from_sse(t);
t->us += interval->us * bias;
if (bias == -1 && interval->us > 0) {
t->sse--;
}
timelib_do_normalize(t);
}

timelib_update_from_sse(t);
if (t->zone_type == TIMELIB_ZONETYPE_ID) {
timelib_set_timezone(t, t->tz_info);
}
Expand Down Expand Up @@ -287,7 +292,11 @@ timelib_time *timelib_sub_wall(timelib_time *old_time, timelib_rel_time *interva

do_range_limit(0, 1000000, 1000000, &interval->us, &interval->s);
t->sse -= bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
timelib_update_from_sse(t);
t->us -= interval->us * bias;
if (bias == -1 && interval->us > 0) {
t->sse++;
}
timelib_do_normalize(t);
}

Expand Down
9 changes: 8 additions & 1 deletion ext/date/lib/parse_date.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ctype.h>
#include <math.h>
#include <assert.h>
#include <limits.h>

#if defined(_MSC_VER)
# define strtoll(s, f, b) _atoi64(s)
Expand Down Expand Up @@ -166,7 +167,13 @@ static const timelib_tz_lookup_table timelib_timezone_utc[] = {
{ "utc", 0, 0, "UTC" },
};

#define MAX_ABBR_LEN 5 /* the longest name in "timezonemap.h" and "fallbackmap.h" */
#if defined(_POSIX_TZNAME_MAX)
# define MAX_ABBR_LEN _POSIX_TZNAME_MAX
#elif defined(TZNAME_MAX)
# define MAX_ABBR_LEN TZNAME_MAX
#else
# define MAX_ABBR_LEN 6
#endif

static timelib_relunit const timelib_relunit_lookup[] = {
{ "ms", TIMELIB_MICROSEC, 1000 },
Expand Down
6 changes: 3 additions & 3 deletions ext/date/lib/timelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
# include "timelib_config.h"
#endif

#define TIMELIB_VERSION 202107
#define TIMELIB_EXTENDED_VERSION 20210701
#define TIMELIB_ASCII_VERSION "2021.07"
#define TIMELIB_VERSION 202108
#define TIMELIB_EXTENDED_VERSION 20210801
#define TIMELIB_ASCII_VERSION "2021.08"

#include <stdlib.h>
#include <stdbool.h>
Expand Down

0 comments on commit 2bf451b

Please sign in to comment.