Import timelib 2022.10

This commit is contained in:
Derick Rethans 2023-11-23 16:06:00 +00:00
parent 20eff14c5c
commit 28dabaab2f
4 changed files with 159 additions and 129 deletions

View File

@ -1,4 +1,4 @@
/* Generated by re2c 1.0.3 on Thu Aug 3 09:42:12 2023 */
/* Generated by re2c 1.0.3 on Thu Nov 23 16:02:28 2023 */
#line 1 "ext/date/lib/parse_date.re"
/*
* The MIT License (MIT)
@ -713,6 +713,17 @@ static const timelib_relunit* timelib_lookup_relunit(const char **ptr)
return value;
}
static void add_with_overflow(Scanner *s, timelib_sll *e, timelib_sll amount, int multiplier)
{
#if defined(__has_builtin) && __has_builtin(__builtin_saddll_overflow)
if (__builtin_saddll_overflow(*e, amount * multiplier, e)) {
add_error(s, TIMELIB_ERR_NUMBER_OUT_OF_RANGE, "Number out of range");
}
#else
*e += (amount * multiplier);
#endif
}
/**
* The time_part parameter is a flag. It can be TIMELIB_TIME_PART_KEEP in case
* the time portion should not be reset to midnight, or
@ -728,13 +739,13 @@ static void timelib_set_relative(const char **ptr, timelib_sll amount, int behav
}
switch (relunit->unit) {
case TIMELIB_MICROSEC: s->time->relative.us += amount * relunit->multiplier; break;
case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break;
case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break;
case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break;
case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break;
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;
case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break;
case TIMELIB_MICROSEC: add_with_overflow(s, &s->time->relative.us, amount, relunit->multiplier); break;
case TIMELIB_SECOND: add_with_overflow(s, &s->time->relative.s, amount, relunit->multiplier); break;
case TIMELIB_MINUTE: add_with_overflow(s, &s->time->relative.i, amount, relunit->multiplier); break;
case TIMELIB_HOUR: add_with_overflow(s, &s->time->relative.h, amount, relunit->multiplier); break;
case TIMELIB_DAY: add_with_overflow(s, &s->time->relative.d, amount, relunit->multiplier); break;
case TIMELIB_MONTH: add_with_overflow(s, &s->time->relative.m, amount, relunit->multiplier); break;
case TIMELIB_YEAR: add_with_overflow(s, &s->time->relative.y, amount, relunit->multiplier); break;
case TIMELIB_WEEKDAY:
TIMELIB_HAVE_WEEKDAY_RELATIVE();
@ -1003,11 +1014,11 @@ static int scan(Scanner *s, timelib_tz_get_wrapper tz_get_wrapper)
std:
s->tok = cursor;
s->len = 0;
#line 1136 "ext/date/lib/parse_date.re"
#line 1147 "ext/date/lib/parse_date.re"
#line 1011 "<stdout>"
#line 1022 "<stdout>"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
@ -1188,23 +1199,23 @@ yy2:
YYDEBUG(2, *YYCURSOR);
++YYCURSOR;
YYDEBUG(3, *YYCURSOR);
#line 1969 "ext/date/lib/parse_date.re"
#line 1980 "ext/date/lib/parse_date.re"
{
s->pos = cursor; s->line++;
goto std;
}
#line 1197 "<stdout>"
#line 1208 "<stdout>"
yy4:
YYDEBUG(4, *YYCURSOR);
++YYCURSOR;
yy5:
YYDEBUG(5, *YYCURSOR);
#line 1975 "ext/date/lib/parse_date.re"
#line 1986 "ext/date/lib/parse_date.re"
{
add_error(s, TIMELIB_ERR_UNEXPECTED_CHARACTER, "Unexpected character");
goto std;
}
#line 1208 "<stdout>"
#line 1219 "<stdout>"
yy6:
YYDEBUG(6, *YYCURSOR);
yyaccept = 0;
@ -1219,11 +1230,11 @@ yy6:
if (yych <= '9') goto yy58;
yy8:
YYDEBUG(8, *YYCURSOR);
#line 1964 "ext/date/lib/parse_date.re"
#line 1975 "ext/date/lib/parse_date.re"
{
goto std;
}
#line 1227 "<stdout>"
#line 1238 "<stdout>"
yy9:
YYDEBUG(9, *YYCURSOR);
yych = *++YYCURSOR;
@ -1257,11 +1268,11 @@ yy11:
YYDEBUG(11, *YYCURSOR);
++YYCURSOR;
YYDEBUG(12, *YYCURSOR);
#line 1959 "ext/date/lib/parse_date.re"
#line 1970 "ext/date/lib/parse_date.re"
{
goto std;
}
#line 1265 "<stdout>"
#line 1276 "<stdout>"
yy13:
YYDEBUG(13, *YYCURSOR);
yyaccept = 1;
@ -1762,7 +1773,7 @@ yy19:
}
yy20:
YYDEBUG(20, *YYCURSOR);
#line 1874 "ext/date/lib/parse_date.re"
#line 1885 "ext/date/lib/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("tzcorrection | tz");
@ -1776,7 +1787,7 @@ yy20:
TIMELIB_DEINIT;
return TIMELIB_TIMEZONE;
}
#line 1780 "<stdout>"
#line 1791 "<stdout>"
yy21:
YYDEBUG(21, *YYCURSOR);
yych = *++YYCURSOR;
@ -3581,7 +3592,7 @@ yy80:
}
yy81:
YYDEBUG(81, *YYCURSOR);
#line 1621 "ext/date/lib/parse_date.re"
#line 1632 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("datenoyearrev");
TIMELIB_INIT;
@ -3592,7 +3603,7 @@ yy81:
TIMELIB_DEINIT;
return TIMELIB_DATE_TEXT;
}
#line 3596 "<stdout>"
#line 3607 "<stdout>"
yy82:
YYDEBUG(82, *YYCURSOR);
yych = *++YYCURSOR;
@ -4107,7 +4118,7 @@ yy112:
}
if (yych == '.') goto yy289;
YYDEBUG(114, *YYCURSOR);
#line 1196 "ext/date/lib/parse_date.re"
#line 1207 "ext/date/lib/parse_date.re"
{
timelib_ull i;
@ -4132,7 +4143,7 @@ yy112:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 4136 "<stdout>"
#line 4147 "<stdout>"
yy115:
YYDEBUG(115, *YYCURSOR);
++YYCURSOR;
@ -5858,7 +5869,7 @@ yy176:
}
yy177:
YYDEBUG(177, *YYCURSOR);
#line 1362 "ext/date/lib/parse_date.re"
#line 1373 "ext/date/lib/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("timetiny24 | timeshort24 | timelong24 | iso8601long");
@ -5885,7 +5896,7 @@ yy177:
TIMELIB_DEINIT;
return TIMELIB_TIME24_WITH_ZONE;
}
#line 5889 "<stdout>"
#line 5900 "<stdout>"
yy178:
YYDEBUG(178, *YYCURSOR);
yyaccept = 4;
@ -6914,7 +6925,7 @@ yy223:
}
yy224:
YYDEBUG(224, *YYCURSOR);
#line 1456 "ext/date/lib/parse_date.re"
#line 1467 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("americanshort | american");
@ -6929,7 +6940,7 @@ yy224:
TIMELIB_DEINIT;
return TIMELIB_AMERICAN;
}
#line 6933 "<stdout>"
#line 6944 "<stdout>"
yy225:
YYDEBUG(225, *YYCURSOR);
yyaccept = 5;
@ -7172,7 +7183,7 @@ yy250:
if (yych <= '9') goto yy431;
yy251:
YYDEBUG(251, *YYCURSOR);
#line 1538 "ext/date/lib/parse_date.re"
#line 1549 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("datefull");
@ -7186,7 +7197,7 @@ yy251:
TIMELIB_DEINIT;
return TIMELIB_DATE_FULL;
}
#line 7190 "<stdout>"
#line 7201 "<stdout>"
yy252:
YYDEBUG(252, *YYCURSOR);
yyaccept = 3;
@ -7300,7 +7311,7 @@ yy259:
if (yych == 'e') goto yy440;
yy260:
YYDEBUG(260, *YYCURSOR);
#line 1943 "ext/date/lib/parse_date.re"
#line 1954 "ext/date/lib/parse_date.re"
{
timelib_ull i;
DEBUG_OUTPUT("relative");
@ -7315,7 +7326,7 @@ yy260:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 7319 "<stdout>"
#line 7330 "<stdout>"
yy261:
YYDEBUG(261, *YYCURSOR);
yych = *++YYCURSOR;
@ -7761,7 +7772,7 @@ yy289:
if (yych <= '9') goto yy471;
yy290:
YYDEBUG(290, *YYCURSOR);
#line 1222 "ext/date/lib/parse_date.re"
#line 1233 "ext/date/lib/parse_date.re"
{
timelib_sll i;
timelib_ull us;
@ -7800,7 +7811,7 @@ yy290:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 7804 "<stdout>"
#line 7815 "<stdout>"
yy291:
YYDEBUG(291, *YYCURSOR);
yych = *++YYCURSOR;
@ -7825,7 +7836,7 @@ yy292:
}
yy293:
YYDEBUG(293, *YYCURSOR);
#line 1784 "ext/date/lib/parse_date.re"
#line 1795 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("ago");
TIMELIB_INIT;
@ -7845,7 +7856,7 @@ yy293:
TIMELIB_DEINIT;
return TIMELIB_AGO;
}
#line 7849 "<stdout>"
#line 7860 "<stdout>"
yy294:
YYDEBUG(294, *YYCURSOR);
yyaccept = 7;
@ -7884,7 +7895,7 @@ yy294:
}
yy295:
YYDEBUG(295, *YYCURSOR);
#line 1864 "ext/date/lib/parse_date.re"
#line 1875 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("monthtext");
TIMELIB_INIT;
@ -7893,7 +7904,7 @@ yy295:
TIMELIB_DEINIT;
return TIMELIB_DATE_TEXT;
}
#line 7897 "<stdout>"
#line 7908 "<stdout>"
yy296:
YYDEBUG(296, *YYCURSOR);
yyaccept = 7;
@ -8468,7 +8479,7 @@ yy314:
}
yy315:
YYDEBUG(315, *YYCURSOR);
#line 1805 "ext/date/lib/parse_date.re"
#line 1816 "ext/date/lib/parse_date.re"
{
const timelib_relunit* relunit;
DEBUG_OUTPUT("daytext");
@ -8485,7 +8496,7 @@ yy315:
TIMELIB_DEINIT;
return TIMELIB_WEEKDAY;
}
#line 8489 "<stdout>"
#line 8500 "<stdout>"
yy316:
YYDEBUG(316, *YYCURSOR);
yych = *++YYCURSOR;
@ -8753,7 +8764,7 @@ yy324:
}
yy325:
YYDEBUG(325, *YYCURSOR);
#line 1607 "ext/date/lib/parse_date.re"
#line 1618 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("datetextual | datenoyear");
@ -8766,7 +8777,7 @@ yy325:
TIMELIB_DEINIT;
return TIMELIB_DATE_TEXT;
}
#line 8770 "<stdout>"
#line 8781 "<stdout>"
yy326:
YYDEBUG(326, *YYCURSOR);
yyaccept = 10;
@ -9460,7 +9471,7 @@ yy350:
}
yy351:
YYDEBUG(351, *YYCURSOR);
#line 1153 "ext/date/lib/parse_date.re"
#line 1164 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("now");
TIMELIB_INIT;
@ -9468,7 +9479,7 @@ yy351:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 9472 "<stdout>"
#line 9483 "<stdout>"
yy352:
YYDEBUG(352, *YYCURSOR);
yyaccept = 2;
@ -10971,7 +10982,7 @@ yy419:
}
yy420:
YYDEBUG(420, *YYCURSOR);
#line 1390 "ext/date/lib/parse_date.re"
#line 1401 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("gnunocolon");
TIMELIB_INIT;
@ -10993,7 +11004,7 @@ yy420:
TIMELIB_DEINIT;
return TIMELIB_GNU_NOCOLON;
}
#line 10997 "<stdout>"
#line 11008 "<stdout>"
yy421:
YYDEBUG(421, *YYCURSOR);
yyaccept = 13;
@ -11074,7 +11085,7 @@ yy421:
}
yy422:
YYDEBUG(422, *YYCURSOR);
#line 1775 "ext/date/lib/parse_date.re"
#line 1786 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("year4");
TIMELIB_INIT;
@ -11082,7 +11093,7 @@ yy422:
TIMELIB_DEINIT;
return TIMELIB_CLF;
}
#line 11086 "<stdout>"
#line 11097 "<stdout>"
yy423:
YYDEBUG(423, *YYCURSOR);
yyaccept = 3;
@ -11689,7 +11700,7 @@ yy456:
YYDEBUG(456, *YYCURSOR);
++YYCURSOR;
YYDEBUG(457, *YYCURSOR);
#line 1324 "ext/date/lib/parse_date.re"
#line 1335 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("timetiny12 | timeshort12 | timelong12");
TIMELIB_INIT;
@ -11706,7 +11717,7 @@ yy456:
TIMELIB_DEINIT;
return TIMELIB_TIME12;
}
#line 11710 "<stdout>"
#line 11721 "<stdout>"
yy458:
YYDEBUG(458, *YYCURSOR);
yych = *++YYCURSOR;
@ -13033,7 +13044,7 @@ yy525:
}
yy526:
YYDEBUG(526, *YYCURSOR);
#line 1162 "ext/date/lib/parse_date.re"
#line 1173 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("noon");
TIMELIB_INIT;
@ -13044,7 +13055,7 @@ yy526:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 13048 "<stdout>"
#line 13059 "<stdout>"
yy527:
YYDEBUG(527, *YYCURSOR);
yyaccept = 2;
@ -14090,7 +14101,7 @@ yy566:
}
yy567:
YYDEBUG(567, *YYCURSOR);
#line 1524 "ext/date/lib/parse_date.re"
#line 1535 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("gnudateshort");
@ -14103,7 +14114,7 @@ yy567:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 14107 "<stdout>"
#line 14118 "<stdout>"
yy568:
YYDEBUG(568, *YYCURSOR);
yyaccept = 15;
@ -14554,7 +14565,7 @@ yy599:
}
yy600:
YYDEBUG(600, *YYCURSOR);
#line 1593 "ext/date/lib/parse_date.re"
#line 1604 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("datenodayrev");
@ -14567,7 +14578,7 @@ yy600:
TIMELIB_DEINIT;
return TIMELIB_DATE_NO_DAY;
}
#line 14571 "<stdout>"
#line 14582 "<stdout>"
yy601:
YYDEBUG(601, *YYCURSOR);
yych = *++YYCURSOR;
@ -15942,7 +15953,7 @@ yy696:
YYDEBUG(696, *YYCURSOR);
++YYCURSOR;
YYDEBUG(697, *YYCURSOR);
#line 1579 "ext/date/lib/parse_date.re"
#line 1590 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("datenoday");
@ -15955,7 +15966,7 @@ yy696:
TIMELIB_DEINIT;
return TIMELIB_DATE_NO_DAY;
}
#line 15959 "<stdout>"
#line 15970 "<stdout>"
yy698:
YYDEBUG(698, *YYCURSOR);
yych = *++YYCURSOR;
@ -16516,7 +16527,7 @@ yy721:
}
yy722:
YYDEBUG(722, *YYCURSOR);
#line 1174 "ext/date/lib/parse_date.re"
#line 1185 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("midnight | today");
TIMELIB_INIT;
@ -16525,7 +16536,7 @@ yy722:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 16529 "<stdout>"
#line 16540 "<stdout>"
yy723:
YYDEBUG(723, *YYCURSOR);
yych = *++YYCURSOR;
@ -16835,7 +16846,7 @@ yy738:
if (yych <= '9') goto yy897;
yy739:
YYDEBUG(739, *YYCURSOR);
#line 1565 "ext/date/lib/parse_date.re"
#line 1576 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("pointed date YY");
@ -16848,7 +16859,7 @@ yy739:
TIMELIB_DEINIT;
return TIMELIB_DATE_FULL_POINTED;
}
#line 16852 "<stdout>"
#line 16863 "<stdout>"
yy740:
YYDEBUG(740, *YYCURSOR);
yyaccept = 15;
@ -16960,7 +16971,7 @@ yy751:
}
yy752:
YYDEBUG(752, *YYCURSOR);
#line 1510 "ext/date/lib/parse_date.re"
#line 1521 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("gnudateshorter");
@ -16973,7 +16984,7 @@ yy752:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 16977 "<stdout>"
#line 16988 "<stdout>"
yy753:
YYDEBUG(753, *YYCURSOR);
yyaccept = 18;
@ -17222,7 +17233,7 @@ yy776:
}
yy777:
YYDEBUG(777, *YYCURSOR);
#line 1436 "ext/date/lib/parse_date.re"
#line 1447 "ext/date/lib/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("iso8601nocolon");
@ -17241,7 +17252,7 @@ yy777:
TIMELIB_DEINIT;
return TIMELIB_ISO_NOCOLON;
}
#line 17245 "<stdout>"
#line 17256 "<stdout>"
yy778:
YYDEBUG(778, *YYCURSOR);
yyaccept = 19;
@ -18469,7 +18480,7 @@ yy848:
}
yy849:
YYDEBUG(849, *YYCURSOR);
#line 1913 "ext/date/lib/parse_date.re"
#line 1924 "ext/date/lib/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz");
@ -18498,7 +18509,7 @@ yy849:
TIMELIB_DEINIT;
return TIMELIB_SHORTDATE_WITH_TIME;
}
#line 18502 "<stdout>"
#line 18513 "<stdout>"
yy850:
YYDEBUG(850, *YYCURSOR);
yyaccept = 20;
@ -19542,7 +19553,7 @@ yy925:
}
yy926:
YYDEBUG(926, *YYCURSOR);
#line 1671 "ext/date/lib/parse_date.re"
#line 1682 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("pgydotd");
@ -19555,7 +19566,7 @@ yy926:
TIMELIB_DEINIT;
return TIMELIB_PG_YEARDAY;
}
#line 19559 "<stdout>"
#line 19570 "<stdout>"
yy927:
YYDEBUG(927, *YYCURSOR);
yyaccept = 21;
@ -19809,7 +19820,7 @@ yy941:
if (yych <= '7') goto yy1059;
yy942:
YYDEBUG(942, *YYCURSOR);
#line 1704 "ext/date/lib/parse_date.re"
#line 1715 "ext/date/lib/parse_date.re"
{
timelib_sll w, d;
DEBUG_OUTPUT("isoweek");
@ -19827,7 +19838,7 @@ yy942:
TIMELIB_DEINIT;
return TIMELIB_ISO_WEEK;
}
#line 19831 "<stdout>"
#line 19842 "<stdout>"
yy943:
YYDEBUG(943, *YYCURSOR);
yych = *++YYCURSOR;
@ -20303,7 +20314,7 @@ yy981:
if (yych == 'e') goto yy1094;
yy982:
YYDEBUG(982, *YYCURSOR);
#line 1847 "ext/date/lib/parse_date.re"
#line 1858 "ext/date/lib/parse_date.re"
{
timelib_sll i;
int behavior = 0;
@ -20319,7 +20330,7 @@ yy982:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 20323 "<stdout>"
#line 20334 "<stdout>"
yy983:
YYDEBUG(983, *YYCURSOR);
yych = *++YYCURSOR;
@ -20666,7 +20677,7 @@ yy1020:
YYDEBUG(1020, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1021, *YYCURSOR);
#line 1553 "ext/date/lib/parse_date.re"
#line 1564 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("pointed date YYYY");
TIMELIB_INIT;
@ -20677,7 +20688,7 @@ yy1020:
TIMELIB_DEINIT;
return TIMELIB_DATE_FULL_POINTED;
}
#line 20681 "<stdout>"
#line 20692 "<stdout>"
yy1022:
YYDEBUG(1022, *YYCURSOR);
++YYCURSOR;
@ -20706,7 +20717,7 @@ yy1024:
}
yy1025:
YYDEBUG(1025, *YYCURSOR);
#line 1484 "ext/date/lib/parse_date.re"
#line 1495 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("iso8601date2");
@ -20719,7 +20730,7 @@ yy1025:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 20723 "<stdout>"
#line 20734 "<stdout>"
yy1026:
YYDEBUG(1026, *YYCURSOR);
yyaccept = 15;
@ -20939,7 +20950,7 @@ yy1042:
}
yy1043:
YYDEBUG(1043, *YYCURSOR);
#line 1472 "ext/date/lib/parse_date.re"
#line 1483 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("iso8601date4 | iso8601date2 | iso8601dateslash | dateslash");
TIMELIB_INIT;
@ -20950,7 +20961,7 @@ yy1043:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 20954 "<stdout>"
#line 20965 "<stdout>"
yy1044:
YYDEBUG(1044, *YYCURSOR);
yyaccept = 26;
@ -21065,7 +21076,7 @@ yy1047:
}
yy1048:
YYDEBUG(1048, *YYCURSOR);
#line 1633 "ext/date/lib/parse_date.re"
#line 1644 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("datenocolon");
TIMELIB_INIT;
@ -21076,7 +21087,7 @@ yy1048:
TIMELIB_DEINIT;
return TIMELIB_DATE_NOCOLON;
}
#line 21080 "<stdout>"
#line 21091 "<stdout>"
yy1049:
YYDEBUG(1049, *YYCURSOR);
yych = *++YYCURSOR;
@ -21146,7 +21157,7 @@ yy1059:
YYDEBUG(1059, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1060, *YYCURSOR);
#line 1685 "ext/date/lib/parse_date.re"
#line 1696 "ext/date/lib/parse_date.re"
{
timelib_sll w, d;
DEBUG_OUTPUT("isoweekday");
@ -21164,7 +21175,7 @@ yy1059:
TIMELIB_DEINIT;
return TIMELIB_ISO_WEEK;
}
#line 21168 "<stdout>"
#line 21179 "<stdout>"
yy1061:
YYDEBUG(1061, *YYCURSOR);
yych = *++YYCURSOR;
@ -21227,7 +21238,7 @@ yy1069:
if (yych <= '9') goto yy1143;
yy1070:
YYDEBUG(1070, *YYCURSOR);
#line 1723 "ext/date/lib/parse_date.re"
#line 1734 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("pgtextshort");
@ -21240,7 +21251,7 @@ yy1070:
TIMELIB_DEINIT;
return TIMELIB_PG_TEXT;
}
#line 21244 "<stdout>"
#line 21255 "<stdout>"
yy1071:
YYDEBUG(1071, *YYCURSOR);
yych = *++YYCURSOR;
@ -21713,7 +21724,7 @@ yy1106:
++YYCURSOR;
yy1107:
YYDEBUG(1107, *YYCURSOR);
#line 1184 "ext/date/lib/parse_date.re"
#line 1195 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("tomorrow");
TIMELIB_INIT;
@ -21724,7 +21735,7 @@ yy1107:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 21728 "<stdout>"
#line 21739 "<stdout>"
yy1108:
YYDEBUG(1108, *YYCURSOR);
yyaccept = 28;
@ -22061,7 +22072,7 @@ yy1140:
YYDEBUG(1140, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1141, *YYCURSOR);
#line 1737 "ext/date/lib/parse_date.re"
#line 1748 "ext/date/lib/parse_date.re"
{
int length = 0;
DEBUG_OUTPUT("pgtextreverse");
@ -22074,7 +22085,7 @@ yy1140:
TIMELIB_DEINIT;
return TIMELIB_PG_TEXT;
}
#line 22078 "<stdout>"
#line 22089 "<stdout>"
yy1142:
YYDEBUG(1142, *YYCURSOR);
++YYCURSOR;
@ -22118,7 +22129,7 @@ yy1144:
}
yy1145:
YYDEBUG(1145, *YYCURSOR);
#line 1279 "ext/date/lib/parse_date.re"
#line 1290 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("backof | frontof");
TIMELIB_INIT;
@ -22140,7 +22151,7 @@ yy1145:
TIMELIB_DEINIT;
return TIMELIB_LF_DAY_OF_MONTH;
}
#line 22144 "<stdout>"
#line 22155 "<stdout>"
yy1146:
YYDEBUG(1146, *YYCURSOR);
yyaccept = 29;
@ -22464,7 +22475,7 @@ yy1171:
}
yy1172:
YYDEBUG(1172, *YYCURSOR);
#line 1823 "ext/date/lib/parse_date.re"
#line 1834 "ext/date/lib/parse_date.re"
{
timelib_sll i;
int behavior = 0;
@ -22487,7 +22498,7 @@ yy1172:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 22491 "<stdout>"
#line 22502 "<stdout>"
yy1173:
YYDEBUG(1173, *YYCURSOR);
yych = *++YYCURSOR;
@ -22499,7 +22510,7 @@ yy1174:
++YYCURSOR;
yy1175:
YYDEBUG(1175, *YYCURSOR);
#line 1141 "ext/date/lib/parse_date.re"
#line 1152 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("yesterday");
TIMELIB_INIT;
@ -22510,7 +22521,7 @@ yy1175:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 22514 "<stdout>"
#line 22525 "<stdout>"
yy1176:
YYDEBUG(1176, *YYCURSOR);
yyaccept = 31;
@ -23003,7 +23014,7 @@ yy1222:
YYDEBUG(1222, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1223, *YYCURSOR);
#line 1889 "ext/date/lib/parse_date.re"
#line 1900 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("dateshortwithtimeshort12 | dateshortwithtimelong12");
TIMELIB_INIT;
@ -23026,7 +23037,7 @@ yy1222:
TIMELIB_DEINIT;
return TIMELIB_SHORTDATE_WITH_TIME;
}
#line 23030 "<stdout>"
#line 23041 "<stdout>"
yy1224:
YYDEBUG(1224, *YYCURSOR);
yych = *++YYCURSOR;
@ -23528,7 +23539,7 @@ yy1268:
YYDEBUG(1268, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1269, *YYCURSOR);
#line 1302 "ext/date/lib/parse_date.re"
#line 1313 "ext/date/lib/parse_date.re"
{
timelib_sll i;
int behavior = 0;
@ -23549,7 +23560,7 @@ yy1268:
TIMELIB_DEINIT;
return TIMELIB_WEEK_DAY_OF_MONTH;
}
#line 23553 "<stdout>"
#line 23564 "<stdout>"
yy1270:
YYDEBUG(1270, *YYCURSOR);
yyaccept = 24;
@ -23596,7 +23607,7 @@ yy1273:
YYDEBUG(1273, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1274, *YYCURSOR);
#line 1262 "ext/date/lib/parse_date.re"
#line 1273 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("firstdayof | lastdayof");
TIMELIB_INIT;
@ -23612,12 +23623,12 @@ yy1273:
TIMELIB_DEINIT;
return TIMELIB_LF_DAY_OF_MONTH;
}
#line 23616 "<stdout>"
#line 23627 "<stdout>"
yy1275:
YYDEBUG(1275, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1276, *YYCURSOR);
#line 1498 "ext/date/lib/parse_date.re"
#line 1509 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("iso8601datex");
TIMELIB_INIT;
@ -23628,7 +23639,7 @@ yy1275:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 23632 "<stdout>"
#line 23643 "<stdout>"
yy1277:
YYDEBUG(1277, *YYCURSOR);
yych = *++YYCURSOR;
@ -23731,7 +23742,7 @@ yy1290:
YYDEBUG(1290, *YYCURSOR);
++YYCURSOR;
YYDEBUG(1291, *YYCURSOR);
#line 1342 "ext/date/lib/parse_date.re"
#line 1353 "ext/date/lib/parse_date.re"
{
DEBUG_OUTPUT("mssqltime");
TIMELIB_INIT;
@ -23750,7 +23761,7 @@ yy1290:
TIMELIB_DEINIT;
return TIMELIB_TIME24_WITH_ZONE;
}
#line 23754 "<stdout>"
#line 23765 "<stdout>"
yy1292:
YYDEBUG(1292, *YYCURSOR);
yych = *++YYCURSOR;
@ -24174,7 +24185,7 @@ yy1328:
if (yych <= '9') goto yy1331;
yy1329:
YYDEBUG(1329, *YYCURSOR);
#line 1645 "ext/date/lib/parse_date.re"
#line 1656 "ext/date/lib/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx | exif");
@ -24199,7 +24210,7 @@ yy1329:
TIMELIB_DEINIT;
return TIMELIB_XMLRPC_SOAP;
}
#line 24203 "<stdout>"
#line 24214 "<stdout>"
yy1330:
YYDEBUG(1330, *YYCURSOR);
yych = *++YYCURSOR;
@ -24569,7 +24580,7 @@ yy1374:
if (yych <= ':') goto yy1383;
yy1375:
YYDEBUG(1375, *YYCURSOR);
#line 1751 "ext/date/lib/parse_date.re"
#line 1762 "ext/date/lib/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("clf");
@ -24592,7 +24603,7 @@ yy1375:
TIMELIB_DEINIT;
return TIMELIB_CLF;
}
#line 24596 "<stdout>"
#line 24607 "<stdout>"
yy1376:
YYDEBUG(1376, *YYCURSOR);
yyaccept = 33;
@ -24824,7 +24835,7 @@ yy1406:
if (yych == ':') goto yy1286;
goto yy1329;
}
#line 1979 "ext/date/lib/parse_date.re"
#line 1990 "ext/date/lib/parse_date.re"
}

View File

@ -711,6 +711,17 @@ static const timelib_relunit* timelib_lookup_relunit(const char **ptr)
return value;
}
static void add_with_overflow(Scanner *s, timelib_sll *e, timelib_sll amount, int multiplier)
{
#if defined(__has_builtin) && __has_builtin(__builtin_saddll_overflow)
if (__builtin_saddll_overflow(*e, amount * multiplier, e)) {
add_error(s, TIMELIB_ERR_NUMBER_OUT_OF_RANGE, "Number out of range");
}
#else
*e += (amount * multiplier);
#endif
}
/**
* The time_part parameter is a flag. It can be TIMELIB_TIME_PART_KEEP in case
* the time portion should not be reset to midnight, or
@ -726,13 +737,13 @@ static void timelib_set_relative(const char **ptr, timelib_sll amount, int behav
}
switch (relunit->unit) {
case TIMELIB_MICROSEC: s->time->relative.us += amount * relunit->multiplier; break;
case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break;
case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break;
case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break;
case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break;
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;
case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break;
case TIMELIB_MICROSEC: add_with_overflow(s, &s->time->relative.us, amount, relunit->multiplier); break;
case TIMELIB_SECOND: add_with_overflow(s, &s->time->relative.s, amount, relunit->multiplier); break;
case TIMELIB_MINUTE: add_with_overflow(s, &s->time->relative.i, amount, relunit->multiplier); break;
case TIMELIB_HOUR: add_with_overflow(s, &s->time->relative.h, amount, relunit->multiplier); break;
case TIMELIB_DAY: add_with_overflow(s, &s->time->relative.d, amount, relunit->multiplier); break;
case TIMELIB_MONTH: add_with_overflow(s, &s->time->relative.m, amount, relunit->multiplier); break;
case TIMELIB_YEAR: add_with_overflow(s, &s->time->relative.y, amount, relunit->multiplier); break;
case TIMELIB_WEEKDAY:
TIMELIB_HAVE_WEEKDAY_RELATIVE();

View File

@ -187,14 +187,22 @@ timelib_long timelib_date_to_int(timelib_time *d, int *error)
void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec)
{
if (h > 0) {
*hour = floor(h);
*min = floor((h - *hour) * 60);
*sec = (h - *hour - ((float) *min / 60)) * 3600;
} else {
*hour = ceil(h);
*min = 0 - ceil((h - *hour) * 60);
*sec = 0 - (h - *hour - ((float) *min / -60)) * 3600;
bool swap = false;
int seconds;
if (h < 0) {
swap = true;
h = fabs(h);
}
*hour = floor(h);
seconds = floor((h - *hour) * 3600);
*min = seconds / 60;
*sec = seconds % 60;
if (swap) {
*hour = 0 - *hour;
}
}

View File

@ -30,9 +30,9 @@
# include "timelib_config.h"
#endif
#define TIMELIB_VERSION 202209
#define TIMELIB_EXTENDED_VERSION 20220901
#define TIMELIB_ASCII_VERSION "2022.09"
#define TIMELIB_VERSION 202210
#define TIMELIB_EXTENDED_VERSION 20221001
#define TIMELIB_ASCII_VERSION "2022.10"
#include <stdlib.h>
#include <stdbool.h>