From: Derick Rethans Date: Tue, 15 Jul 2008 17:38:27 +0000 (+0000) Subject: - MFH: Also add the warnings for times. This does not make sense for the X-Git-Tag: php-5.3.0alpha1~330 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3df7836db9456aadcec7239864c49d7d6f8eb1d1;p=php - MFH: Also add the warnings for times. This does not make sense for the english text parser, as invalid times are never allowed in there. --- diff --git a/ext/date/lib/dow.c b/ext/date/lib/dow.c index bd12d82fc7..50f10587da 100644 --- a/ext/date/lib/dow.c +++ b/ext/date/lib/dow.c @@ -140,6 +140,14 @@ timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll return day + ((w - 1) * 7) + d; } +int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s) +{ + if (h < 0 || h > 23 || i < 0 || i > 59 || s < 0 || s > 59) { + return 0; + } + return 1; +} + int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d) { if (m < 1 || m > 12 || d < 1 || d > timelib_days_in_month(y, m)) { diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index 69663a7c1d..dd0984c8b6 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Mon Jul 14 19:34:39 2008 */ +/* Generated by re2c 0.13.5 on Tue Jul 15 19:21:36 2008 */ #line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ @@ -23630,6 +23630,12 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim } } + /* do funky checking whether the parsed time was valid time */ + if (s->time->h != TIMELIB_UNSET && s->time->i != TIMELIB_UNSET && + s->time->s != TIMELIB_UNSET && + !timelib_valid_time( s->time->h, s->time->i, s->time->s)) { + add_pbf_warning(s, "The parsed time was invalid", string, ptr); + } /* do funky checking whether the parsed date was valid date */ if (s->time->y != TIMELIB_UNSET && s->time->m != TIMELIB_UNSET && s->time->d != TIMELIB_UNSET && diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index d538ea7510..14bd7e88db 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -2040,6 +2040,12 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim } } + /* do funky checking whether the parsed time was valid time */ + if (s->time->h != TIMELIB_UNSET && s->time->i != TIMELIB_UNSET && + s->time->s != TIMELIB_UNSET && + !timelib_valid_time( s->time->h, s->time->i, s->time->s)) { + add_pbf_warning(s, "The parsed time was invalid", string, ptr); + } /* do funky checking whether the parsed date was valid date */ if (s->time->y != TIMELIB_UNSET && s->time->m != TIMELIB_UNSET && s->time->d != TIMELIB_UNSET && diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h index 2023482748..f23978f89a 100644 --- a/ext/date/lib/timelib.h +++ b/ext/date/lib/timelib.h @@ -56,6 +56,7 @@ timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d); timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m); void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy); +int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s); int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d); /* From parse_date.re */