php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42913 Allow checkdate() to validate time parameters
Submitted: 2007-10-10 10:49 UTC Modified: 2018-03-29 22:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: RQuadling at GMail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 5.2.4 OS: irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-10-10 10:49 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-29 22:24 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Date/time related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Sep 15 18:01:27 2019 UTC