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: 2021-07-30 10:22 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: RQuadling at GMail dot com Assigned: cmb (profile)
Status: Wont fix Package: Date/time related
PHP Version: 5.2.4 OS: irrelevant
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-29 22:24 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Date/time related
 [2021-07-30 10:22 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-07-30 10:22 UTC] cmb@php.net
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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC