From 89af1000b2148c43c31213be00d39eb178dc54d0 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Tue, 15 Jul 2008 17:37:33 +0000 Subject: [PATCH] - Also add the warnings for times. This does not make sense for the english text parser, as invalid times are never allowed in there. --- ext/date/lib/dow.c | 8 ++++++++ ext/date/lib/parse_date.c | 8 +++++++- ext/date/lib/parse_date.re | 6 ++++++ ext/date/lib/timelib.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) 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 01247e35e1..b03c53bac3 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:27:22 2008 */ +/* Generated by re2c 0.13.5 on Tue Jul 15 19:35:53 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 */ -- 2.40.0