From: RQuadling at GMail dot com
Operating system: irrelevant
PHP version: 5.2.4
PHP Bug Type: Feature/Change Request
Bug description: Allow checkdate() to validate time parameters
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 bug report at http://bugs.php.net/?id=42913&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42913&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42913&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42913&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42913&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42913&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42913&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42913&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42913&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42913&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42913&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42913&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42913&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42913&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42913&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42913&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42913&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42913&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42913&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42913&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42913&r=mysqlcfg