[BUGFIX] Fix fatal error for date validation in EXT:form on Windows 30/35530/5
authorStephan Großberndt <stephan@grossberndt.de>
Wed, 17 Dec 2014 00:54:14 +0000 (01:54 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 19 Jan 2015 21:43:52 +0000 (22:43 +0100)
Use a mapping to date_create_from_format() in date validation of
EXT:form if strptime() is not available. This prevents a fatal error on
Windows because strptime() is not implemented on Windows platform.

Resolves: #63945
Releases: master, 6.2
Change-Id: I92f66597ce362cc8dae66b09ba19ed428055a6de
Reviewed-on: http://review.typo3.org/35530
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/form/Classes/Validation/DateValidator.php

index 3401a3d..f0bb948 100644 (file)
@@ -54,11 +54,31 @@ class DateValidator extends \TYPO3\CMS\Form\Validation\AbstractValidator {
        public function isValid() {
                if ($this->requestHandler->has($this->fieldName)) {
                        $value = $this->requestHandler->getByMethod($this->fieldName);
-                       $parsedDate = strptime($value, $this->format);
-                       $parsedDateYear = $parsedDate['tm_year'] + 1900;
-                       $parsedDateMonth = $parsedDate['tm_mon'] + 1;
-                       $parsedDateDay = $parsedDate['tm_mday'];
-                       return checkdate($parsedDateMonth, $parsedDateDay, $parsedDateYear);
+                       if (function_exists('strptime')) {
+                               $parsedDate = strptime($value, $this->format);
+                               $parsedDateYear = $parsedDate['tm_year'] + 1900;
+                               $parsedDateMonth = $parsedDate['tm_mon'] + 1;
+                               $parsedDateDay = $parsedDate['tm_mday'];
+                               return checkdate($parsedDateMonth, $parsedDateDay, $parsedDateYear);
+                       } else {
+                               // %a => D : An abbreviated textual representation of the day (conversion works only for english)
+                               // %A => l : A full textual representation of the day (conversion works only for english)
+                               // %d => d : Day of the month, 2 digits with leading zeros
+                               // %e => j : Day of the month, 2 digits without leading zeros
+                               // %j => z : Day of the year, 3 digits with leading zeros
+                               // %b => M : Abbreviated month name, based on the locale (conversion works only for english)
+                               // %B => F : Full month name, based on the locale (conversion works only for english)
+                               // %h => M : Abbreviated month name, based on the locale (an alias of %b) (conversion works only for english)
+                               // %m => m : Two digit representation of the month
+                               // %y => y : Two digit representation of the year
+                               // %Y => Y : Four digit representation for the year
+                               $dateTimeFormat = str_replace(
+                                       array('%a', '%A', '%d', '%e', '%j', '%b', '%B', '%h', '%m', '%y', '%Y'),
+                                       array('D', 'l', 'd', 'j', 'z', 'M', 'F', 'M', 'm', 'y', 'Y'),
+                                       $this->format
+                               );
+                               return date_create_from_format($dateTimeFormat, $value) !== FALSE;
+                       }
                }
                return TRUE;
        }