Skip to content

Commit 119163a

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Update timelib to 2022.17, which has fixes for PHP bugs
2 parents 9bd15cf + d83851d commit 119163a

6 files changed

Lines changed: 35 additions & 42 deletions

File tree

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ PHP NEWS
1212
. Fixed bug GH-22602 (gregoriantojd() and juliantojd() integer overflow with
1313
INT_MAX year). (arshidkv12)
1414

15+
- Date:
16+
. Update timelib to 2022.17. (Derick)
17+
. Fixed bug GH-19803 (Parsing a string with a single white space does create
18+
an error). (Derick)
19+
. Fixed Unix timestamps in February of the year 0 are misparsed with
20+
@-notation. (LukasGelbmann)
21+
1522
- DBA:
1623
. Fixed OOB read on malformed length field in dba flatfile handler. (alhudz)
1724

ext/date/lib/parse_date.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ static timelib_ull timelib_get_signed_nr(Scanner *s, const char **ptr, int max_l
555555
int len = 0;
556556

557557
/* Skip over non-numeric chars */
558-
559558
while (((**ptr < '0') || (**ptr > '9')) && (**ptr != '+') && (**ptr != '-')) {
560559
if (**ptr == '\0') {
561560
add_error(s, TIMELIB_ERR_UNEXPECTED_DATA, "Found unexpected data");
@@ -569,6 +568,7 @@ static timelib_ull timelib_get_signed_nr(Scanner *s, const char **ptr, int max_l
569568
str[0] = '+'; /* First position is the sign */
570569
str_ptr = str + 1;
571570

571+
572572
while ((**ptr == '+') || (**ptr == '-')) {
573573
if (**ptr == '-') {
574574
str[0] = str[0] == '+' ? '-' : '+';
@@ -2020,7 +2020,7 @@ timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_contain
20202020
in.errors->error_messages = NULL;
20212021

20222022
if (len > 0) {
2023-
while (isspace((unsigned char)*s) && s < e) {
2023+
while (isspace((unsigned char)*s) && s <= e) {
20242024
s++;
20252025
}
20262026
while (isspace((unsigned char)*e) && e > s) {

ext/date/lib/timelib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
# include "timelib_config.h"
3131
#endif
3232

33-
#define TIMELIB_VERSION 202215
34-
#define TIMELIB_EXTENDED_VERSION 20221501
35-
#define TIMELIB_ASCII_VERSION "2022.15"
33+
#define TIMELIB_VERSION 202217
34+
#define TIMELIB_EXTENDED_VERSION 20221701
35+
#define TIMELIB_ASCII_VERSION "2022.17"
3636

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

ext/date/lib/timelib_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
#ifndef TIMELIB_HAVE_BUILTIN_SADDLL_OVERFLOW
136136
# define TIMELIB_HAVE_BUILTIN_SADDLL_OVERFLOW 0
137137
#endif
138+
138139
struct _ttinfo
139140
{
140141
int32_t offset;
@@ -165,6 +166,7 @@ extern "C" {
165166
#endif
166167

167168
/* From unixtime2tm.c */
169+
void timelib_date_from_epoch_days(timelib_sll epoch_days, timelib_sll *y, timelib_sll *m, timelib_sll *d);
168170
int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
169171

170172
/* From parse_posix.c */

ext/date/lib/tm2unixtime.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -197,32 +197,6 @@ void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
197197
do_range_limit(0, 12, 12, &rt->m, &rt->y);
198198
}
199199

200-
static void magic_date_calc(timelib_time *time)
201-
{
202-
timelib_sll y, ddd, mi, mm, dd, g;
203-
204-
/* The algorithm doesn't work before the year 1 */
205-
if (time->d < -719498) {
206-
return;
207-
}
208-
209-
g = time->d + HINNANT_EPOCH_SHIFT - 1;
210-
211-
y = (10000 * g + 14780) / 3652425;
212-
ddd = g - ((365*y) + (y/4) - (y/100) + (y/400));
213-
if (ddd < 0) {
214-
y--;
215-
ddd = g - ((365*y) + (y/4) - (y/100) + (y/400));
216-
}
217-
mi = (100 * ddd + 52) / 3060;
218-
mm = ((mi + 2) % 12) + 1;
219-
y = y + (mi + 2) / 12;
220-
dd = ddd - ((mi * 306 + 5) / 10) + 1;
221-
time->y = y;
222-
time->m = mm;
223-
time->d = dd;
224-
}
225-
226200
void timelib_do_normalize(timelib_time* time)
227201
{
228202
if (time->us != TIMELIB_UNSET) do_range_limit(0, 1000000, 1000000, &time->us, &time->s);
@@ -232,8 +206,9 @@ void timelib_do_normalize(timelib_time* time)
232206
do_range_limit(1, 13, 12, &time->m, &time->y);
233207

234208
/* Short cut if we're doing things against the Epoch */
235-
if (time->y == 1970 && time->m == 1 && time->d != 1) {
236-
magic_date_calc(time);
209+
if (time->y == 1970 && time->m == 1) {
210+
timelib_date_from_epoch_days(time->d - 1, &time->y, &time->m, &time->d);
211+
return;
237212
}
238213

239214
do {} while (do_range_limit_days(&time->y, &time->m, &time->d));

ext/date/lib/unixtime2tm.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@
2626
#include "timelib.h"
2727
#include "timelib_private.h"
2828

29-
void timelib_unixtime2date(timelib_sll ts, timelib_sll *y, timelib_sll *m, timelib_sll *d)
29+
/* Converts Unix epoch days (days since 1970-01-01) to a date. Algorithm from:
30+
* http://howardhinnant.github.io/date_algorithms.html#civil_from_days */
31+
void timelib_date_from_epoch_days(timelib_sll epoch_days, timelib_sll *y, timelib_sll *m, timelib_sll *d)
3032
{
31-
timelib_sll days, era, t;
33+
timelib_sll days, era;
3234
timelib_ull day_of_era, year_of_era, day_of_year, month_portion;
3335

3436
/* Calculate days since algorithm's epoch (0000-03-01) */
35-
days = ts / SECS_PER_DAY + HINNANT_EPOCH_SHIFT;
36-
37-
/* Adjustment for a negative time portion */
38-
t = ts % SECS_PER_DAY;
39-
days += (t < 0) ? -1 : 0;
37+
days = epoch_days + HINNANT_EPOCH_SHIFT;
4038

41-
/* Calculate year, month, and day. Algorithm from:
42-
* http://howardhinnant.github.io/date_algorithms.html#civil_from_days */
4339
era = (days >= 0 ? days : days - DAYS_PER_ERA + 1) / DAYS_PER_ERA;
4440
day_of_era = days - era * DAYS_PER_ERA;
4541
year_of_era = (day_of_era - day_of_era / 1460 + day_of_era / 36524 - day_of_era / 146096) / DAYS_PER_YEAR;
@@ -49,6 +45,19 @@ void timelib_unixtime2date(timelib_sll ts, timelib_sll *y, timelib_sll *m, timel
4945
*d = day_of_year - (153 * month_portion + 2) / 5 + 1;
5046
*m = month_portion + (month_portion < 10 ? 3 : -9);
5147
*y += (*m <= 2);
48+
}
49+
50+
void timelib_unixtime2date(timelib_sll ts, timelib_sll *y, timelib_sll *m, timelib_sll *d)
51+
{
52+
timelib_sll epoch_days, t;
53+
54+
epoch_days = ts / SECS_PER_DAY;
55+
56+
/* Adjustment for a negative time portion */
57+
t = ts % SECS_PER_DAY;
58+
epoch_days += (t < 0) ? -1 : 0;
59+
60+
timelib_date_from_epoch_days(epoch_days, y, m, d);
5261

5362
TIMELIB_DEBUG(printf("A: ts=%lld, year=%lld, month=%lld, day=%lld,", ts, *y, *m, *d););
5463
}

0 commit comments

Comments
 (0)