DateUtil::checkDate() now validates all ISO dates
authorAlexander Ebert <ebert@woltlab.com>
Wed, 12 Mar 2014 16:03:05 +0000 (17:03 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 12 Mar 2014 16:03:05 +0000 (17:03 +0100)
Fixes #1677

wcfsetup/install/files/lib/util/DateUtil.class.php

index 496e58a1be903663e149a1b470416a3017e51ec4..ce6acfd2e73f291e22cd5d8396652c3dd8e76df2 100644 (file)
@@ -357,6 +357,12 @@ final class DateUtil {
         * @param       string          $date
         */
        public static function validateDate($date) {
+               if (preg_match('~^(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})~', $date, $matches)) {
+                       return checkdate($matches['month'], $matches['day'], $matches['year']);
+               }
+               
+               return false;
+               
                // matches almost any valid date between year 2000 and 2038
                if (!preg_match('~^(20[0-2][0-9]|203[0-8])\-(0[1-9]|1[0-2])\-(0[1-9]|[1-2][0-9]|3[0-1])$~', $date)) {
                        throw new SystemException("date '".$date."' is invalid, violating ISO-8601 date format.");