]> granicus.if.org Git - php/commitdiff
- MFH: Added a warning to the error struct in case a parsed-date was found to
authorDerick Rethans <derick@php.net>
Mon, 14 Jul 2008 17:36:12 +0000 (17:36 +0000)
committerDerick Rethans <derick@php.net>
Mon, 14 Jul 2008 17:36:12 +0000 (17:36 +0000)
  be invalid.

ext/date/lib/dow.c
ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/lib/timelib.h
ext/date/php_date.c

index def1b3e59e4ec88324a7ae45494f4a83cdd66240..bd12d82fc7802c7e96137b734b326216530eaba3 100644 (file)
@@ -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)
 {
index 6a4c68eebf7cfb1717693b0c612d6a3835d6ce52..69663a7c1d206a9470b94b86c2609dfacefa19a5 100644 (file)
@@ -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;
index da4f5248d197d4d221e48c2b8114379777ae60ca..d538ea7510decbd54d8380940ef3c26741b93617 100644 (file)
@@ -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;
index 1afe0e4ef660acb0abf098b08814cb7613d1bd75..20234827480065d02fdaa413b69adca41ba79799 100644 (file)
@@ -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);
index 78629444a382f25798d3d930d6ffb7d2032a2878..bcfc9405a1e71a677699bd3893197c584c47509c 100644 (file)
@@ -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 */