Req #42913 [Opn->Wfx]: Allow checkdate() to validate time parameters

From: Date: Fri, 30 Jul 2021 10:22:13 +0000
Subject: Req #42913 [Opn->Wfx]: Allow checkdate() to validate time parameters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235470@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=42913&edit=1 ID: 42913 Updated by: cmb@php.net Reported by: RQuadling at GMail dot com Summary: Allow checkdate() to validate time parameters -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Date/time related Operating System: irrelevant PHP Version: 5.2.4 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Apparently, this isn't one of the most wanted features, and I seriously doubt its usefulness, especially if it wouldn't account for leap seconds. If anybody still feels this would be a good feature addition, please pursue the RFC process[1]. [1] <https://wiki.php.net/rfc/howto> Previous Comments: ------------------------------------------------------------------------ [2007-10-10 10:49:28] RQuadling at GMail dot com Description: ------------ I would like to extend the checkdate() function to optionally allow validation of hour/minutes/seconds. Patch: Index: php_date.c =================================================================== RCS file: /repository/php-src/ext/date/php_date.c,v retrieving revision 1.146 diff -u -r1.146 php_date.c --- php_date.c 27 Sep 2007 18:28:38 -0000 1.146 +++ php_date.c 10 Oct 2007 10:14:53 -0000 @@ -1368,20 +1368,29 @@ /* }}} */ -/* {{{ proto bool checkdate(int month, int day, int year) +/* {{{ proto bool checkdate(int month, int day, int year [, int hour, int minute, int second]) Returns true(1) if it is a valid date in gregorian calendar */ PHP_FUNCTION(checkdate) { - long m, d, y; + long m, d, y, h, n, s; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &m, &d, &y) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|lll", &m, &d, &y, &h, &n, &s) == FAILURE) { RETURN_FALSE; } + if (3 != ZEND_NUM_ARGS() && 6 != ZEND_NUM_ARGS()) { + WRONG_PARAM_COUNT; + } + if (y < 1 || y > 32767 || m < 1 || m > 12 || d < 1 || d > timelib_days_in_month(y, m)) { RETURN_FALSE; } - RETURN_TRUE; /* True : This month, day, year arguments are valid */ + + if (6 == ZEND_NUM_ARGS() && (h < 0 || h > 23 || n < 0 || n > 59 || s < 0 || s > 59) { + RETURN_FALSE; + } + + RETURN_TRUE; /* True : This month, day, year arguments are valid and if supplied, so is the hour, minutes and seconds */ } /* }}} */ Also available at http://rquadling.php1h.com/php_date.c_checkdate_supports_time.diff.txt And doc patch is at and assumes a 5.3 change (that's me being hopeful) http://rquadling.php1h.com/checkdate.xml_checkdate_supports_time.diff.txt ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=42913&edit=1

« previous php.bugs (#235470) next »