Skip to content

Commit 0dcd098

Browse files
committed
Merge remote-tracking branch 'derickr/timelib-2021-17-integration' into PHP-8.1
2 parents 50dc7a8 + dd365b0 commit 0dcd098

File tree

9 files changed

+175
-138
lines changed

9 files changed

+175
-138
lines changed

ext/date/lib/parse_date.c

Lines changed: 115 additions & 114 deletions
Large diffs are not rendered by default.

ext/date/lib/parse_date.re

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static timelib_error_message *alloc_error_message(timelib_error_message **messag
360360
return *messages + (*count)++;
361361
}
362362

363-
static void add_warning(Scanner *s, int error_code, char *error)
363+
static void add_warning(Scanner *s, int error_code, const char *error)
364364
{
365365
timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count);
366366

@@ -370,7 +370,7 @@ static void add_warning(Scanner *s, int error_code, char *error)
370370
message->message = timelib_strdup(error);
371371
}
372372

373-
static void add_error(Scanner *s, int error_code, char *error)
373+
static void add_error(Scanner *s, int error_code, const char *error)
374374
{
375375
timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count);
376376

@@ -380,7 +380,7 @@ static void add_error(Scanner *s, int error_code, char *error)
380380
message->message = timelib_strdup(error);
381381
}
382382

383-
static void add_pbf_warning(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr)
383+
static void add_pbf_warning(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr)
384384
{
385385
timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count);
386386

@@ -390,7 +390,7 @@ static void add_pbf_warning(Scanner *s, int error_code, char *error, const char
390390
message->message = timelib_strdup(error);
391391
}
392392

393-
static void add_pbf_error(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr)
393+
static void add_pbf_error(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr)
394394
{
395395
timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count);
396396

@@ -520,7 +520,6 @@ static timelib_sll timelib_get_frac_nr(const char **ptr)
520520
const char *begin, *end;
521521
char *str;
522522
double tmp_nr = TIMELIB_UNSET;
523-
int len = 0;
524523

525524
while ((**ptr != '.') && (**ptr != ':') && ((**ptr < '0') || (**ptr > '9'))) {
526525
if (**ptr == '\0') {
@@ -531,7 +530,6 @@ static timelib_sll timelib_get_frac_nr(const char **ptr)
531530
begin = *ptr;
532531
while ((**ptr == '.') || (**ptr == ':') || ((**ptr >= '0') && (**ptr <= '9'))) {
533532
++*ptr;
534-
++len;
535533
}
536534
end = *ptr;
537535
str = timelib_calloc(1, end - begin);
@@ -2611,15 +2609,18 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
26112609
if (parsed->h == TIMELIB_UNSET) parsed->h = now->h != TIMELIB_UNSET ? now->h : 0;
26122610
if (parsed->i == TIMELIB_UNSET) parsed->i = now->i != TIMELIB_UNSET ? now->i : 0;
26132611
if (parsed->s == TIMELIB_UNSET) parsed->s = now->s != TIMELIB_UNSET ? now->s : 0;
2614-
if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0;
2615-
if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0;
26162612

2617-
if (!parsed->tz_abbr) {
2618-
parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL;
2619-
}
26202613
if (!parsed->tz_info) {
26212614
parsed->tz_info = now->tz_info ? (!(options & TIMELIB_NO_CLONE) ? timelib_tzinfo_clone(now->tz_info) : now->tz_info) : NULL;
2615+
2616+
if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0;
2617+
if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0;
2618+
2619+
if (!parsed->tz_abbr) {
2620+
parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL;
2621+
}
26222622
}
2623+
26232624
if (parsed->zone_type == 0 && now->zone_type != 0) {
26242625
parsed->zone_type = now->zone_type;
26252626
/* parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL;
@@ -2631,7 +2632,7 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
26312632
*/
26322633
}
26332634

2634-
char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst)
2635+
const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst)
26352636
{
26362637
const timelib_tz_lookup_table *tp;
26372638

ext/date/lib/parse_iso_intervals.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Generated by re2c 0.15.3 on Sun Jun 26 17:34:21 2022 */
1+
/* Generated by re2c 0.15.3 on Wed Sep 14 10:36:13 2022 */
22
#line 1 "ext/date/lib/parse_iso_intervals.re"
33
/*
44
* The MIT License (MIT)
@@ -88,7 +88,7 @@ typedef struct _Scanner {
8888
int have_end_date;
8989
} Scanner;
9090

91-
static void add_error(Scanner *s, char *error)
91+
static void add_error(Scanner *s, const char *error)
9292
{
9393
s->errors->error_count++;
9494
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));

ext/date/lib/parse_iso_intervals.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef struct _Scanner {
8686
int have_end_date;
8787
} Scanner;
8888

89-
static void add_error(Scanner *s, char *error)
89+
static void add_error(Scanner *s, const char *error)
9090
{
9191
s->errors->error_count++;
9292
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));

ext/date/lib/timelib.h

Lines changed: 7 additions & 7 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 202116
34-
#define TIMELIB_EXTENDED_VERSION 20211601
35-
#define TIMELIB_ASCII_VERSION "2021.16"
33+
#define TIMELIB_VERSION 202117
34+
#define TIMELIB_EXTENDED_VERSION 20211701
35+
#define TIMELIB_ASCII_VERSION "2021.17"
3636

3737
#include <stdlib.h>
3838
#include <stdbool.h>
@@ -342,10 +342,10 @@ typedef struct _timelib_error_container {
342342
} timelib_error_container;
343343

344344
typedef struct _timelib_tz_lookup_table {
345-
char *name;
345+
const char *name;
346346
int type;
347347
float gmtoffset;
348-
char *full_tz_name;
348+
const char *full_tz_name;
349349
} timelib_tz_lookup_table;
350350

351351
typedef struct _timelib_tzdb_index_entry {
@@ -354,7 +354,7 @@ typedef struct _timelib_tzdb_index_entry {
354354
} timelib_tzdb_index_entry;
355355

356356
typedef struct _timelib_tzdb {
357-
char *version;
357+
const char *version;
358358
int index_size;
359359
const timelib_tzdb_index_entry *index;
360360
const unsigned char *data;
@@ -583,7 +583,7 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
583583
*
584584
* The returned char* is not duplicated, and should not be freed.
585585
*/
586-
char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
586+
const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
587587

588588
/* Returns an array of known time zone abbreviations
589589
*

ext/date/lib/timelib_private.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@
112112
m = NULL; \
113113
}
114114

115+
#if defined (__GNUC__)
116+
# define TIMELIB_GNUC_CHECK_VERSION(major, minor) \
117+
((__GNUC__ > (major)) || \
118+
((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor))))
119+
#else
120+
# define TIMELIB_GNUC_CHECK_VERSION(major, minor) 0
121+
#endif
122+
123+
#if TIMELIB_GNUC_CHECK_VERSION(7, 0)
124+
# define TIMELIB_BREAK_INTENTIONALLY_MISSING __attribute__ ((fallthrough));
125+
#else
126+
# define TIMELIB_BREAK_INTENTIONALLY_MISSING
127+
#endif
128+
115129
struct _ttinfo
116130
{
117131
int32_t offset;

ext/date/lib/tm2unixtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static void do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
372372

373373
case TIMELIB_ZONETYPE_ID:
374374
tzi = tz->tz_info;
375-
/* Break intentionally missing */
375+
TIMELIB_BREAK_INTENTIONALLY_MISSING
376376

377377
default: {
378378
/* No timezone in struct, fallback to reference if possible */

ext/date/php_date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3585,7 +3585,7 @@ PHP_FUNCTION(timezone_name_get)
35853585
PHP_FUNCTION(timezone_name_from_abbr)
35863586
{
35873587
zend_string *abbr;
3588-
char *tzid;
3588+
const char *tzid;
35893589
zend_long gmtoffset = -1;
35903590
zend_long isdst = -1;
35913591

ext/date/tests/gh9165.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-9165 (strtotime translates a date-time with DST/non-DST hour differently based on default timezone)
3+
--FILE--
4+
<?php
5+
date_default_timezone_set('America/Lower_Princes');
6+
echo strtotime("2018-10-28 01:00:00 Europe/London") . PHP_EOL;
7+
8+
date_default_timezone_set('Europe/London');
9+
echo strtotime("2018-10-28 01:00:00 Europe/London"). PHP_EOL;
10+
11+
date_default_timezone_set('America/Lower_Princes');
12+
echo strtotime("2018-10-28 04:00:00 Europe/London") . PHP_EOL;
13+
14+
date_default_timezone_set('Europe/London');
15+
echo strtotime("2018-10-28 04:00:00 Europe/London"). PHP_EOL;
16+
?>
17+
--EXPECT--
18+
1540684800
19+
1540684800
20+
1540699200
21+
1540699200

0 commit comments

Comments
 (0)