From: Derick Rethans Date: Mon, 14 Jul 2008 17:36:12 +0000 (+0000) Subject: - MFH: Added a warning to the error struct in case a parsed-date was found to X-Git-Tag: php-5.3.0alpha1~349 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c76ba173a91d9503c0912f3b546ca5aa9c45cb61;p=php - MFH: Added a warning to the error struct in case a parsed-date was found to be invalid. --- diff --git a/ext/date/lib/dow.c b/ext/date/lib/dow.c index def1b3e59e..bd12d82fc7 100644 --- a/ext/date/lib/dow.c +++ b/ext/date/lib/dow.c @@ -140,6 +140,13 @@ timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll return day + ((w - 1) * 7) + d; } +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)) { + return 0; + } + return 1; +} #if 0 int main(void) { diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index 6a4c68eebf..69663a7c1d 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 Fri Jul 11 10:39:11 2008 */ +/* Generated by re2c 0.13.5 on Mon Jul 14 19:34:39 2008 */ #line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ @@ -23358,6 +23358,11 @@ timelib_time* timelib_strtotime(char *s, int len, struct timelib_error_container #endif } while(t != EOI); + /* do funky checking whether the parsed date was valid date */ + if (in.time->have_date && !timelib_valid_date( in.time->y, in.time->m, in.time->d)) { + add_warning(&in, "The parsed date was invalid"); + } + free(in.str); if (errors) { *errors = in.errors; @@ -23625,6 +23630,12 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim } } + /* 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 && + !timelib_valid_date( s->time->y, s->time->m, s->time->d)) { + add_pbf_warning(s, "The parsed date was invalid", string, ptr); + } if (errors) { *errors = in.errors; diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index da4f5248d1..d538ea7510 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -1768,6 +1768,11 @@ timelib_time* timelib_strtotime(char *s, int len, struct timelib_error_container #endif } while(t != EOI); + /* do funky checking whether the parsed date was valid date */ + if (in.time->have_date && !timelib_valid_date( in.time->y, in.time->m, in.time->d)) { + add_warning(&in, "The parsed date was invalid"); + } + free(in.str); if (errors) { *errors = in.errors; @@ -2035,6 +2040,12 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim } } + /* 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 && + !timelib_valid_date( s->time->y, s->time->m, s->time->d)) { + add_pbf_warning(s, "The parsed date was invalid", string, ptr); + } if (errors) { *errors = in.errors; diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h index 1afe0e4ef6..2023482748 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_date(timelib_sll y, timelib_sll m, timelib_sll d); /* From parse_date.re */ timelib_time *timelib_strtotime(char *s, int len, timelib_error_container **errors, const timelib_tzdb *tzdb); diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 78629444a3..bcfc9405a1 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1610,7 +1610,7 @@ PHP_FUNCTION(checkdate) RETURN_FALSE; } - if (y < 1 || y > 32767 || m < 1 || m > 12 || d < 1 || d > timelib_days_in_month(y, m)) { + if (y < 1 || y > 32767 || timelib_valid_date(y, m, d)) { RETURN_FALSE; } RETURN_TRUE; /* True : This month, day, year arguments are valid */