From 4a5202293b1510f984a0805e0cc1417f17e36a37 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 14 Sep 2022 10:35:49 +0100 Subject: [PATCH 1/3] Merge timelib 2021.17 --- ext/date/lib/parse_date.c | 229 ++++++++++++++-------------- ext/date/lib/parse_date.re | 25 +-- ext/date/lib/parse_iso_intervals.c | 4 +- ext/date/lib/parse_iso_intervals.re | 2 +- ext/date/lib/timelib.h | 14 +- ext/date/lib/timelib_private.h | 14 ++ ext/date/lib/tm2unixtime.c | 2 +- 7 files changed, 153 insertions(+), 137 deletions(-) diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index 6e4c6247258..64ad3a0ba08 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.15.3 on Sun Jun 26 17:34:01 2022 */ +/* Generated by re2c 0.15.3 on Wed Sep 14 10:36:03 2022 */ #line 1 "ext/date/lib/parse_date.re" /* * The MIT License (MIT) @@ -362,7 +362,7 @@ static timelib_error_message *alloc_error_message(timelib_error_message **messag return *messages + (*count)++; } -static void add_warning(Scanner *s, int error_code, char *error) +static void add_warning(Scanner *s, int error_code, const char *error) { timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count); @@ -372,7 +372,7 @@ static void add_warning(Scanner *s, int error_code, char *error) message->message = timelib_strdup(error); } -static void add_error(Scanner *s, int error_code, char *error) +static void add_error(Scanner *s, int error_code, const char *error) { timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count); @@ -382,7 +382,7 @@ static void add_error(Scanner *s, int error_code, char *error) message->message = timelib_strdup(error); } -static void add_pbf_warning(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr) +static void add_pbf_warning(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr) { timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count); @@ -392,7 +392,7 @@ static void add_pbf_warning(Scanner *s, int error_code, char *error, const char message->message = timelib_strdup(error); } -static void add_pbf_error(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr) +static void add_pbf_error(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr) { timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count); @@ -522,7 +522,6 @@ static timelib_sll timelib_get_frac_nr(const char **ptr) const char *begin, *end; char *str; double tmp_nr = TIMELIB_UNSET; - int len = 0; while ((**ptr != '.') && (**ptr != ':') && ((**ptr < '0') || (**ptr > '9'))) { if (**ptr == '\0') { @@ -533,7 +532,6 @@ static timelib_sll timelib_get_frac_nr(const char **ptr) begin = *ptr; while ((**ptr == '.') || (**ptr == ':') || ((**ptr >= '0') && (**ptr <= '9'))) { ++*ptr; - ++len; } end = *ptr; str = timelib_calloc(1, end - begin); @@ -954,11 +952,11 @@ static int scan(Scanner *s, timelib_tz_get_wrapper tz_get_wrapper) std: s->tok = cursor; s->len = 0; -#line 1085 "ext/date/lib/parse_date.re" +#line 1083 "ext/date/lib/parse_date.re" -#line 962 "" +#line 960 "" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1096,7 +1094,7 @@ yy2: } yy3: YYDEBUG(3, *YYCURSOR); -#line 1819 "ext/date/lib/parse_date.re" +#line 1817 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("tzcorrection | tz"); @@ -1109,7 +1107,7 @@ yy3: TIMELIB_DEINIT; return TIMELIB_TIMEZONE; } -#line 1113 "" +#line 1111 "" yy4: YYDEBUG(4, *YYCURSOR); yych = *++YYCURSOR; @@ -1416,12 +1414,12 @@ yy11: if (yych <= '9') goto yy1483; yy12: YYDEBUG(12, *YYCURSOR); -#line 1914 "ext/date/lib/parse_date.re" +#line 1912 "ext/date/lib/parse_date.re" { add_error(s, TIMELIB_ERR_UNEXPECTED_CHARACTER, "Unexpected character"); goto std; } -#line 1425 "" +#line 1423 "" yy13: YYDEBUG(13, *YYCURSOR); yych = *++YYCURSOR; @@ -2665,11 +2663,11 @@ yy48: if (yych <= '9') goto yy54; yy49: YYDEBUG(49, *YYCURSOR); -#line 1903 "ext/date/lib/parse_date.re" +#line 1901 "ext/date/lib/parse_date.re" { goto std; } -#line 2673 "" +#line 2671 "" yy50: YYDEBUG(50, *YYCURSOR); yych = *++YYCURSOR; @@ -2678,12 +2676,12 @@ yy51: YYDEBUG(51, *YYCURSOR); ++YYCURSOR; YYDEBUG(52, *YYCURSOR); -#line 1908 "ext/date/lib/parse_date.re" +#line 1906 "ext/date/lib/parse_date.re" { s->pos = cursor; s->line++; goto std; } -#line 2687 "" +#line 2685 "" yy53: YYDEBUG(53, *YYCURSOR); yych = *++YYCURSOR; @@ -3105,7 +3103,7 @@ yy83: if (yych == 's') goto yy85; yy84: YYDEBUG(84, *YYCURSOR); -#line 1887 "ext/date/lib/parse_date.re" +#line 1885 "ext/date/lib/parse_date.re" { timelib_ull i; DEBUG_OUTPUT("relative"); @@ -3120,7 +3118,7 @@ yy84: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 3124 "" +#line 3122 "" yy85: YYDEBUG(85, *YYCURSOR); yych = *++YYCURSOR; @@ -4129,7 +4127,7 @@ yy218: } yy219: YYDEBUG(219, *YYCURSOR); -#line 1750 "ext/date/lib/parse_date.re" +#line 1748 "ext/date/lib/parse_date.re" { const timelib_relunit* relunit; DEBUG_OUTPUT("daytext"); @@ -4146,7 +4144,7 @@ yy219: TIMELIB_DEINIT; return TIMELIB_WEEKDAY; } -#line 4150 "" +#line 4148 "" yy220: YYDEBUG(220, *YYCURSOR); yych = *++YYCURSOR; @@ -4692,7 +4690,7 @@ yy247: } yy248: YYDEBUG(248, *YYCURSOR); -#line 1809 "ext/date/lib/parse_date.re" +#line 1807 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("monthtext"); TIMELIB_INIT; @@ -4701,7 +4699,7 @@ yy248: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 4705 "" +#line 4703 "" yy249: YYDEBUG(249, *YYCURSOR); ++YYCURSOR; @@ -4950,7 +4948,7 @@ yy261: goto yy267; yy262: YYDEBUG(262, *YYCURSOR); -#line 1555 "ext/date/lib/parse_date.re" +#line 1553 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datetextual | datenoyear"); @@ -4963,7 +4961,7 @@ yy262: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 4967 "" +#line 4965 "" yy263: YYDEBUG(263, *YYCURSOR); yyaccept = 6; @@ -5090,7 +5088,7 @@ yy275: } yy276: YYDEBUG(276, *YYCURSOR); -#line 1857 "ext/date/lib/parse_date.re" +#line 1855 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz"); @@ -5119,7 +5117,7 @@ yy276: TIMELIB_DEINIT; return TIMELIB_SHORTDATE_WITH_TIME; } -#line 5123 "" +#line 5121 "" yy277: YYDEBUG(277, *YYCURSOR); yyaccept = 7; @@ -5417,7 +5415,7 @@ yy300: YYDEBUG(300, *YYCURSOR); ++YYCURSOR; YYDEBUG(301, *YYCURSOR); -#line 1833 "ext/date/lib/parse_date.re" +#line 1831 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("dateshortwithtimeshort12 | dateshortwithtimelong12"); TIMELIB_INIT; @@ -5440,7 +5438,7 @@ yy300: TIMELIB_DEINIT; return TIMELIB_SHORTDATE_WITH_TIME; } -#line 5444 "" +#line 5442 "" yy302: YYDEBUG(302, *YYCURSOR); yych = *++YYCURSOR; @@ -6118,7 +6116,7 @@ yy361: YYDEBUG(362, *YYCURSOR); ++YYCURSOR; YYDEBUG(363, *YYCURSOR); -#line 1527 "ext/date/lib/parse_date.re" +#line 1525 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datenoday"); @@ -6131,7 +6129,7 @@ yy361: TIMELIB_DEINIT; return TIMELIB_DATE_NO_DAY; } -#line 6135 "" +#line 6133 "" yy364: YYDEBUG(364, *YYCURSOR); yych = *++YYCURSOR; @@ -6362,7 +6360,7 @@ yy368: if (yych <= '9') goto yy372; yy371: YYDEBUG(371, *YYCURSOR); -#line 1671 "ext/date/lib/parse_date.re" +#line 1669 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pgtextshort"); @@ -6375,7 +6373,7 @@ yy371: TIMELIB_DEINIT; return TIMELIB_PG_TEXT; } -#line 6379 "" +#line 6377 "" yy372: YYDEBUG(372, *YYCURSOR); yych = *++YYCURSOR; @@ -6957,7 +6955,7 @@ yy397: } yy398: YYDEBUG(398, *YYCURSOR); -#line 1729 "ext/date/lib/parse_date.re" +#line 1727 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("ago"); TIMELIB_INIT; @@ -6977,7 +6975,7 @@ yy398: TIMELIB_DEINIT; return TIMELIB_AGO; } -#line 6981 "" +#line 6979 "" yy399: YYDEBUG(399, *YYCURSOR); yyaccept = 5; @@ -8766,7 +8764,7 @@ yy460: ++YYCURSOR; yy461: YYDEBUG(461, *YYCURSOR); -#line 1420 "ext/date/lib/parse_date.re" +#line 1418 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("iso8601date4 | iso8601date2 | iso8601dateslash | dateslash"); TIMELIB_INIT; @@ -8777,7 +8775,7 @@ yy461: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 8781 "" +#line 8779 "" yy462: YYDEBUG(462, *YYCURSOR); yych = *++YYCURSOR; @@ -8899,7 +8897,7 @@ yy484: YYDEBUG(484, *YYCURSOR); ++YYCURSOR; YYDEBUG(485, *YYCURSOR); -#line 1446 "ext/date/lib/parse_date.re" +#line 1444 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("iso8601datex"); TIMELIB_INIT; @@ -8910,7 +8908,7 @@ yy484: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 8914 "" +#line 8912 "" yy486: YYDEBUG(486, *YYCURSOR); yyaccept = 1; @@ -9664,7 +9662,7 @@ yy508: } yy509: YYDEBUG(509, *YYCURSOR); -#line 1569 "ext/date/lib/parse_date.re" +#line 1567 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenoyearrev"); TIMELIB_INIT; @@ -9675,7 +9673,7 @@ yy509: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 9679 "" +#line 9677 "" yy510: YYDEBUG(510, *YYCURSOR); yyaccept = 9; @@ -9816,7 +9814,7 @@ yy521: YYDEBUG(521, *YYCURSOR); ++YYCURSOR; YYDEBUG(522, *YYCURSOR); -#line 1273 "ext/date/lib/parse_date.re" +#line 1271 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("timetiny12 | timeshort12 | timelong12"); TIMELIB_INIT; @@ -9832,7 +9830,7 @@ yy521: TIMELIB_DEINIT; return TIMELIB_TIME12; } -#line 9836 "" +#line 9834 "" yy523: YYDEBUG(523, *YYCURSOR); yyaccept = 10; @@ -9845,7 +9843,7 @@ yy523: } yy524: YYDEBUG(524, *YYCURSOR); -#line 1310 "ext/date/lib/parse_date.re" +#line 1308 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("timetiny24 | timeshort24 | timelong24 | iso8601long"); @@ -9872,7 +9870,7 @@ yy524: TIMELIB_DEINIT; return TIMELIB_TIME24_WITH_ZONE; } -#line 9876 "" +#line 9874 "" yy525: YYDEBUG(525, *YYCURSOR); yyaccept = 10; @@ -10185,7 +10183,7 @@ yy556: YYDEBUG(556, *YYCURSOR); ++YYCURSOR; YYDEBUG(557, *YYCURSOR); -#line 1290 "ext/date/lib/parse_date.re" +#line 1288 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("mssqltime"); TIMELIB_INIT; @@ -10204,7 +10202,7 @@ yy556: TIMELIB_DEINIT; return TIMELIB_TIME24_WITH_ZONE; } -#line 10208 "" +#line 10206 "" yy558: YYDEBUG(558, *YYCURSOR); yyaccept = 10; @@ -10310,7 +10308,7 @@ yy567: if (yych <= '9') goto yy574; yy568: YYDEBUG(568, *YYCURSOR); -#line 1486 "ext/date/lib/parse_date.re" +#line 1484 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datefull"); @@ -10324,7 +10322,7 @@ yy568: TIMELIB_DEINIT; return TIMELIB_DATE_FULL; } -#line 10328 "" +#line 10326 "" yy569: YYDEBUG(569, *YYCURSOR); yych = *++YYCURSOR; @@ -11060,7 +11058,7 @@ yy638: YYDEBUG(639, *YYCURSOR); ++YYCURSOR; YYDEBUG(640, *YYCURSOR); -#line 1501 "ext/date/lib/parse_date.re" +#line 1499 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pointed date YYYY"); TIMELIB_INIT; @@ -11071,7 +11069,7 @@ yy638: TIMELIB_DEINIT; return TIMELIB_DATE_FULL_POINTED; } -#line 11075 "" +#line 11073 "" yy641: YYDEBUG(641, *YYCURSOR); yyaccept = 10; @@ -11107,7 +11105,7 @@ yy644: if (yych <= '9') goto yy638; yy645: YYDEBUG(645, *YYCURSOR); -#line 1513 "ext/date/lib/parse_date.re" +#line 1511 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pointed date YY"); @@ -11120,7 +11118,7 @@ yy645: TIMELIB_DEINIT; return TIMELIB_DATE_FULL_POINTED; } -#line 11124 "" +#line 11122 "" yy646: YYDEBUG(646, *YYCURSOR); yyaccept = 10; @@ -11761,7 +11759,7 @@ yy689: } yy690: YYDEBUG(690, *YYCURSOR); -#line 1472 "ext/date/lib/parse_date.re" +#line 1470 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("gnudateshort"); @@ -11774,7 +11772,7 @@ yy690: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 11778 "" +#line 11776 "" yy691: YYDEBUG(691, *YYCURSOR); yyaccept = 12; @@ -11880,7 +11878,7 @@ yy699: } yy700: YYDEBUG(700, *YYCURSOR); -#line 1404 "ext/date/lib/parse_date.re" +#line 1402 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("americanshort | american"); @@ -11895,7 +11893,7 @@ yy700: TIMELIB_DEINIT; return TIMELIB_AMERICAN; } -#line 11899 "" +#line 11897 "" yy701: YYDEBUG(701, *YYCURSOR); yyaccept = 13; @@ -12129,7 +12127,7 @@ yy733: if (yych <= ':') goto yy737; yy734: YYDEBUG(734, *YYCURSOR); -#line 1699 "ext/date/lib/parse_date.re" +#line 1697 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("clf"); @@ -12149,7 +12147,7 @@ yy734: TIMELIB_DEINIT; return TIMELIB_CLF; } -#line 12153 "" +#line 12151 "" yy735: YYDEBUG(735, *YYCURSOR); yyaccept = 14; @@ -12769,7 +12767,7 @@ yy807: } yy808: YYDEBUG(808, *YYCURSOR); -#line 1432 "ext/date/lib/parse_date.re" +#line 1430 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("iso8601date2"); @@ -12782,7 +12780,7 @@ yy808: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 12786 "" +#line 12784 "" yy809: YYDEBUG(809, *YYCURSOR); yych = *++YYCURSOR; @@ -12821,7 +12819,7 @@ yy815: YYDEBUG(815, *YYCURSOR); ++YYCURSOR; YYDEBUG(816, *YYCURSOR); -#line 1685 "ext/date/lib/parse_date.re" +#line 1683 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pgtextreverse"); @@ -12834,7 +12832,7 @@ yy815: TIMELIB_DEINIT; return TIMELIB_PG_TEXT; } -#line 12838 "" +#line 12836 "" yy817: YYDEBUG(817, *YYCURSOR); yych = *++YYCURSOR; @@ -12999,7 +12997,7 @@ yy827: } yy828: YYDEBUG(828, *YYCURSOR); -#line 1720 "ext/date/lib/parse_date.re" +#line 1718 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("year4"); TIMELIB_INIT; @@ -13007,7 +13005,7 @@ yy828: TIMELIB_DEINIT; return TIMELIB_CLF; } -#line 13011 "" +#line 13009 "" yy829: YYDEBUG(829, *YYCURSOR); yych = *++YYCURSOR; @@ -13212,7 +13210,7 @@ yy837: } yy838: YYDEBUG(838, *YYCURSOR); -#line 1541 "ext/date/lib/parse_date.re" +#line 1539 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datenodayrev"); @@ -13225,7 +13223,7 @@ yy838: TIMELIB_DEINIT; return TIMELIB_DATE_NO_DAY; } -#line 13229 "" +#line 13227 "" yy839: YYDEBUG(839, *YYCURSOR); yych = *++YYCURSOR; @@ -13446,7 +13444,7 @@ yy858: if (yych <= '7') goto yy861; yy859: YYDEBUG(859, *YYCURSOR); -#line 1652 "ext/date/lib/parse_date.re" +#line 1650 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweek"); @@ -13464,7 +13462,7 @@ yy859: TIMELIB_DEINIT; return TIMELIB_ISO_WEEK; } -#line 13468 "" +#line 13466 "" yy860: YYDEBUG(860, *YYCURSOR); yych = *++YYCURSOR; @@ -13474,7 +13472,7 @@ yy861: YYDEBUG(861, *YYCURSOR); ++YYCURSOR; YYDEBUG(862, *YYCURSOR); -#line 1633 "ext/date/lib/parse_date.re" +#line 1631 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweekday"); @@ -13492,7 +13490,7 @@ yy861: TIMELIB_DEINIT; return TIMELIB_ISO_WEEK; } -#line 13496 "" +#line 13494 "" yy863: YYDEBUG(863, *YYCURSOR); yych = *++YYCURSOR; @@ -13564,7 +13562,7 @@ yy865: } yy866: YYDEBUG(866, *YYCURSOR); -#line 1619 "ext/date/lib/parse_date.re" +#line 1617 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pgydotd"); @@ -13577,7 +13575,7 @@ yy866: TIMELIB_DEINIT; return TIMELIB_PG_YEARDAY; } -#line 13581 "" +#line 13579 "" yy867: YYDEBUG(867, *YYCURSOR); yych = *++YYCURSOR; @@ -13680,7 +13678,7 @@ yy886: ++YYCURSOR; yy887: YYDEBUG(887, *YYCURSOR); -#line 1593 "ext/date/lib/parse_date.re" +#line 1591 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx | exif"); @@ -13705,7 +13703,7 @@ yy887: TIMELIB_DEINIT; return TIMELIB_XMLRPC_SOAP; } -#line 13709 "" +#line 13707 "" yy888: YYDEBUG(888, *YYCURSOR); yych = *++YYCURSOR; @@ -14001,7 +13999,7 @@ yy892: } yy893: YYDEBUG(893, *YYCURSOR); -#line 1581 "ext/date/lib/parse_date.re" +#line 1579 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenocolon"); TIMELIB_INIT; @@ -14012,7 +14010,7 @@ yy893: TIMELIB_DEINIT; return TIMELIB_DATE_NOCOLON; } -#line 14016 "" +#line 14014 "" yy894: YYDEBUG(894, *YYCURSOR); yych = *++YYCURSOR; @@ -14934,7 +14932,7 @@ yy1017: } yy1018: YYDEBUG(1018, *YYCURSOR); -#line 1458 "ext/date/lib/parse_date.re" +#line 1456 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("gnudateshorter"); @@ -14947,7 +14945,7 @@ yy1018: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 14951 "" +#line 14949 "" yy1019: YYDEBUG(1019, *YYCURSOR); yyaccept = 22; @@ -16155,7 +16153,7 @@ yy1125: } yy1127: YYDEBUG(1127, *YYCURSOR); -#line 1338 "ext/date/lib/parse_date.re" +#line 1336 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("gnunocolon"); TIMELIB_INIT; @@ -16177,7 +16175,7 @@ yy1127: TIMELIB_DEINIT; return TIMELIB_GNU_NOCOLON; } -#line 16181 "" +#line 16179 "" yy1128: YYDEBUG(1128, *YYCURSOR); yych = *++YYCURSOR; @@ -16277,7 +16275,7 @@ yy1134: } yy1135: YYDEBUG(1135, *YYCURSOR); -#line 1384 "ext/date/lib/parse_date.re" +#line 1382 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("iso8601nocolon"); @@ -16296,7 +16294,7 @@ yy1135: TIMELIB_DEINIT; return TIMELIB_ISO_NOCOLON; } -#line 16300 "" +#line 16298 "" yy1136: YYDEBUG(1136, *YYCURSOR); yyaccept = 25; @@ -17272,7 +17270,7 @@ yy1178: } yy1179: YYDEBUG(1179, *YYCURSOR); -#line 1792 "ext/date/lib/parse_date.re" +#line 1790 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -17288,7 +17286,7 @@ yy1179: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 17292 "" +#line 17290 "" yy1180: YYDEBUG(1180, *YYCURSOR); ++YYCURSOR; @@ -17354,7 +17352,7 @@ yy1188: YYDEBUG(1188, *YYCURSOR); ++YYCURSOR; YYDEBUG(1189, *YYCURSOR); -#line 1251 "ext/date/lib/parse_date.re" +#line 1249 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -17375,7 +17373,7 @@ yy1188: TIMELIB_DEINIT; return TIMELIB_WEEK_DAY_OF_MONTH; } -#line 17379 "" +#line 17377 "" yy1190: YYDEBUG(1190, *YYCURSOR); yyaccept = 26; @@ -17515,7 +17513,7 @@ yy1205: } yy1206: YYDEBUG(1206, *YYCURSOR); -#line 1768 "ext/date/lib/parse_date.re" +#line 1766 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -17538,7 +17536,7 @@ yy1206: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 17542 "" +#line 17540 "" yy1207: YYDEBUG(1207, *YYCURSOR); yych = *++YYCURSOR; @@ -20487,7 +20485,7 @@ yy1387: } yy1388: YYDEBUG(1388, *YYCURSOR); -#line 1228 "ext/date/lib/parse_date.re" +#line 1226 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("backof | frontof"); TIMELIB_INIT; @@ -20509,7 +20507,7 @@ yy1388: TIMELIB_DEINIT; return TIMELIB_LF_DAY_OF_MONTH; } -#line 20513 "" +#line 20511 "" yy1389: YYDEBUG(1389, *YYCURSOR); yyaccept = 28; @@ -20808,7 +20806,7 @@ yy1410: YYDEBUG(1410, *YYCURSOR); ++YYCURSOR; YYDEBUG(1411, *YYCURSOR); -#line 1211 "ext/date/lib/parse_date.re" +#line 1209 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("firstdayof | lastdayof"); TIMELIB_INIT; @@ -20824,7 +20822,7 @@ yy1410: TIMELIB_DEINIT; return TIMELIB_LF_DAY_OF_MONTH; } -#line 20828 "" +#line 20826 "" yy1412: YYDEBUG(1412, *YYCURSOR); yyaccept = 1; @@ -22346,7 +22344,7 @@ yy1483: if (yych <= '9') goto yy1483; yy1485: YYDEBUG(1485, *YYCURSOR); -#line 1145 "ext/date/lib/parse_date.re" +#line 1143 "ext/date/lib/parse_date.re" { timelib_ull i; @@ -22371,7 +22369,7 @@ yy1485: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22375 "" +#line 22373 "" yy1486: YYDEBUG(1486, *YYCURSOR); ++YYCURSOR; @@ -22379,7 +22377,7 @@ yy1486: if (yych <= '9') goto yy1488; yy1487: YYDEBUG(1487, *YYCURSOR); -#line 1171 "ext/date/lib/parse_date.re" +#line 1169 "ext/date/lib/parse_date.re" { timelib_sll i; timelib_ull us; @@ -22418,7 +22416,7 @@ yy1487: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22422 "" +#line 22420 "" yy1488: YYDEBUG(1488, *YYCURSOR); yych = *++YYCURSOR; @@ -22887,7 +22885,7 @@ yy1523: ++YYCURSOR; yy1524: YYDEBUG(1524, *YYCURSOR); -#line 1133 "ext/date/lib/parse_date.re" +#line 1131 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("tomorrow"); TIMELIB_INIT; @@ -22898,7 +22896,7 @@ yy1524: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22902 "" +#line 22900 "" yy1525: YYDEBUG(1525, *YYCURSOR); yych = *++YYCURSOR; @@ -22933,7 +22931,7 @@ yy1526: } yy1527: YYDEBUG(1527, *YYCURSOR); -#line 1123 "ext/date/lib/parse_date.re" +#line 1121 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("midnight | today"); TIMELIB_INIT; @@ -22942,7 +22940,7 @@ yy1527: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22946 "" +#line 22944 "" yy1528: YYDEBUG(1528, *YYCURSOR); yych = *++YYCURSOR; @@ -25037,7 +25035,7 @@ yy1611: } yy1612: YYDEBUG(1612, *YYCURSOR); -#line 1102 "ext/date/lib/parse_date.re" +#line 1100 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("now"); TIMELIB_INIT; @@ -25045,7 +25043,7 @@ yy1612: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 25049 "" +#line 25047 "" yy1613: YYDEBUG(1613, *YYCURSOR); yych = *++YYCURSOR; @@ -25184,7 +25182,7 @@ yy1619: } yy1620: YYDEBUG(1620, *YYCURSOR); -#line 1111 "ext/date/lib/parse_date.re" +#line 1109 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("noon"); TIMELIB_INIT; @@ -25195,7 +25193,7 @@ yy1620: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 25199 "" +#line 25197 "" yy1621: YYDEBUG(1621, *YYCURSOR); yyaccept = 1; @@ -25728,7 +25726,7 @@ yy1642: ++YYCURSOR; yy1643: YYDEBUG(1643, *YYCURSOR); -#line 1090 "ext/date/lib/parse_date.re" +#line 1088 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("yesterday"); TIMELIB_INIT; @@ -25739,7 +25737,7 @@ yy1643: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 25743 "" +#line 25741 "" yy1644: YYDEBUG(1644, *YYCURSOR); yyaccept = 1; @@ -25912,7 +25910,7 @@ yy1649: goto yy1643; } } -#line 1918 "ext/date/lib/parse_date.re" +#line 1916 "ext/date/lib/parse_date.re" } @@ -26609,15 +26607,18 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options) if (parsed->h == TIMELIB_UNSET) parsed->h = now->h != TIMELIB_UNSET ? now->h : 0; if (parsed->i == TIMELIB_UNSET) parsed->i = now->i != TIMELIB_UNSET ? now->i : 0; if (parsed->s == TIMELIB_UNSET) parsed->s = now->s != TIMELIB_UNSET ? now->s : 0; - if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0; - if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0; - if (!parsed->tz_abbr) { - parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL; - } if (!parsed->tz_info) { parsed->tz_info = now->tz_info ? (!(options & TIMELIB_NO_CLONE) ? timelib_tzinfo_clone(now->tz_info) : now->tz_info) : NULL; + + if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0; + if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0; + + if (!parsed->tz_abbr) { + parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL; + } } + if (parsed->zone_type == 0 && now->zone_type != 0) { parsed->zone_type = now->zone_type; /* parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL; @@ -26629,7 +26630,7 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options) */ } -char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst) +const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst) { const timelib_tz_lookup_table *tp; diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 11b0be0d4a6..403f98d5eae 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -360,7 +360,7 @@ static timelib_error_message *alloc_error_message(timelib_error_message **messag return *messages + (*count)++; } -static void add_warning(Scanner *s, int error_code, char *error) +static void add_warning(Scanner *s, int error_code, const char *error) { timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count); @@ -370,7 +370,7 @@ static void add_warning(Scanner *s, int error_code, char *error) message->message = timelib_strdup(error); } -static void add_error(Scanner *s, int error_code, char *error) +static void add_error(Scanner *s, int error_code, const char *error) { timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count); @@ -380,7 +380,7 @@ static void add_error(Scanner *s, int error_code, char *error) message->message = timelib_strdup(error); } -static void add_pbf_warning(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr) +static void add_pbf_warning(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr) { timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count); @@ -390,7 +390,7 @@ static void add_pbf_warning(Scanner *s, int error_code, char *error, const char message->message = timelib_strdup(error); } -static void add_pbf_error(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr) +static void add_pbf_error(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr) { timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count); @@ -520,7 +520,6 @@ static timelib_sll timelib_get_frac_nr(const char **ptr) const char *begin, *end; char *str; double tmp_nr = TIMELIB_UNSET; - int len = 0; while ((**ptr != '.') && (**ptr != ':') && ((**ptr < '0') || (**ptr > '9'))) { if (**ptr == '\0') { @@ -531,7 +530,6 @@ static timelib_sll timelib_get_frac_nr(const char **ptr) begin = *ptr; while ((**ptr == '.') || (**ptr == ':') || ((**ptr >= '0') && (**ptr <= '9'))) { ++*ptr; - ++len; } end = *ptr; str = timelib_calloc(1, end - begin); @@ -2611,15 +2609,18 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options) if (parsed->h == TIMELIB_UNSET) parsed->h = now->h != TIMELIB_UNSET ? now->h : 0; if (parsed->i == TIMELIB_UNSET) parsed->i = now->i != TIMELIB_UNSET ? now->i : 0; if (parsed->s == TIMELIB_UNSET) parsed->s = now->s != TIMELIB_UNSET ? now->s : 0; - if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0; - if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0; - if (!parsed->tz_abbr) { - parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL; - } if (!parsed->tz_info) { parsed->tz_info = now->tz_info ? (!(options & TIMELIB_NO_CLONE) ? timelib_tzinfo_clone(now->tz_info) : now->tz_info) : NULL; + + if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0; + if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0; + + if (!parsed->tz_abbr) { + parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL; + } } + if (parsed->zone_type == 0 && now->zone_type != 0) { parsed->zone_type = now->zone_type; /* 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) */ } -char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst) +const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst) { const timelib_tz_lookup_table *tp; diff --git a/ext/date/lib/parse_iso_intervals.c b/ext/date/lib/parse_iso_intervals.c index 900443ae267..a467da3471f 100644 --- a/ext/date/lib/parse_iso_intervals.c +++ b/ext/date/lib/parse_iso_intervals.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.15.3 on Sun Jun 26 17:34:21 2022 */ +/* Generated by re2c 0.15.3 on Wed Sep 14 10:36:13 2022 */ #line 1 "ext/date/lib/parse_iso_intervals.re" /* * The MIT License (MIT) @@ -88,7 +88,7 @@ typedef struct _Scanner { int have_end_date; } Scanner; -static void add_error(Scanner *s, char *error) +static void add_error(Scanner *s, const char *error) { s->errors->error_count++; s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message)); diff --git a/ext/date/lib/parse_iso_intervals.re b/ext/date/lib/parse_iso_intervals.re index bd4015a323a..2a394156f98 100644 --- a/ext/date/lib/parse_iso_intervals.re +++ b/ext/date/lib/parse_iso_intervals.re @@ -86,7 +86,7 @@ typedef struct _Scanner { int have_end_date; } Scanner; -static void add_error(Scanner *s, char *error) +static void add_error(Scanner *s, const char *error) { s->errors->error_count++; s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message)); diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h index f6868427980..dbdddd34f7b 100644 --- a/ext/date/lib/timelib.h +++ b/ext/date/lib/timelib.h @@ -30,9 +30,9 @@ # include "timelib_config.h" #endif -#define TIMELIB_VERSION 202116 -#define TIMELIB_EXTENDED_VERSION 20211601 -#define TIMELIB_ASCII_VERSION "2021.16" +#define TIMELIB_VERSION 202117 +#define TIMELIB_EXTENDED_VERSION 20211701 +#define TIMELIB_ASCII_VERSION "2021.17" #include #include @@ -342,10 +342,10 @@ typedef struct _timelib_error_container { } timelib_error_container; typedef struct _timelib_tz_lookup_table { - char *name; + const char *name; int type; float gmtoffset; - char *full_tz_name; + const char *full_tz_name; } timelib_tz_lookup_table; typedef struct _timelib_tzdb_index_entry { @@ -354,7 +354,7 @@ typedef struct _timelib_tzdb_index_entry { } timelib_tzdb_index_entry; typedef struct _timelib_tzdb { - char *version; + const char *version; int index_size; const timelib_tzdb_index_entry *index; const unsigned char *data; @@ -583,7 +583,7 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options); * * The returned char* is not duplicated, and should not be freed. */ -char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst); +const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst); /* Returns an array of known time zone abbreviations * diff --git a/ext/date/lib/timelib_private.h b/ext/date/lib/timelib_private.h index 2015a15dbf7..65ec6b014b8 100644 --- a/ext/date/lib/timelib_private.h +++ b/ext/date/lib/timelib_private.h @@ -112,6 +112,20 @@ m = NULL; \ } +#if defined (__GNUC__) +# define TIMELIB_GNUC_CHECK_VERSION(major, minor) \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor)))) +#else +# define TIMELIB_GNUC_CHECK_VERSION(major, minor) 0 +#endif + +#if TIMELIB_GNUC_CHECK_VERSION(7, 0) +# define TIMELIB_BREAK_INTENTIONALLY_MISSING __attribute__ ((fallthrough)); +#else +# define TIMELIB_BREAK_INTENTIONALLY_MISSING +#endif + struct _ttinfo { int32_t offset; diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c index 7740b25e97e..b1ab6bd89f4 100644 --- a/ext/date/lib/tm2unixtime.c +++ b/ext/date/lib/tm2unixtime.c @@ -372,7 +372,7 @@ static void do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi) case TIMELIB_ZONETYPE_ID: tzi = tz->tz_info; - /* Break intentionally missing */ + TIMELIB_BREAK_INTENTIONALLY_MISSING default: { /* No timezone in struct, fallback to reference if possible */ From e5b4624b8b03e01ccde2f6a9e25a2446c8527f6a Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 14 Sep 2022 10:42:28 +0100 Subject: [PATCH 2/3] Fixed #9165: strtotime translates a date-time with DST/non-DST hour differently based on default timezone --- NEWS | 4 ++++ ext/date/tests/gh9165.phpt | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ext/date/tests/gh9165.phpt diff --git a/NEWS b/NEWS index 451c0ed2ae1..8312e9798a5 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ PHP NEWS . Fixed bug GH-9447 (Invalid class FQN emitted by AST dump for new and class constants in constant expressions). (ilutov) +- Date: + . Fixed bug GH-9165 (strtotime translates a date-time with DST/non-DST hour + differently based on default timezone). (Derick) + - DOM: . Fixed bug #79451 (DOMDocument->replaceChild on doctype causes double free). (Nathan Freeman) diff --git a/ext/date/tests/gh9165.phpt b/ext/date/tests/gh9165.phpt new file mode 100644 index 00000000000..d5dce2a1c08 --- /dev/null +++ b/ext/date/tests/gh9165.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-9165 (strtotime translates a date-time with DST/non-DST hour differently based on default timezone) +--FILE-- + +--EXPECT-- +1540684800 +1540684800 +1540699200 +1540699200 From dd365b044ad53a8af9d7443d2c0742065ad98e31 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 14 Sep 2022 11:02:26 +0100 Subject: [PATCH 3/3] Add 'const' to match actual API --- ext/date/php_date.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 3e5de97c663..9844618b5b8 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3585,7 +3585,7 @@ PHP_FUNCTION(timezone_name_get) PHP_FUNCTION(timezone_name_from_abbr) { zend_string *abbr; - char *tzid; + const char *tzid; zend_long gmtoffset = -1; zend_long isdst = -1;