diff --git a/Civi/FormProcessor/Type/DateType.php b/Civi/FormProcessor/Type/DateType.php index e444845221db94a8b5b810989b1963bc7e684c81..a8ac83a1b5d44f5290449e8d4e678bf888d68b8b 100644 --- a/Civi/FormProcessor/Type/DateType.php +++ b/Civi/FormProcessor/Type/DateType.php @@ -75,12 +75,7 @@ public function normalizeValue($value) { if ($value) { // transform date format to avoid DateTime issues - $format = $this->configuration->get('format'); - $fixFormats = ["dmY", "mdY", "m-d-Y", "dmYHis", "dmYhis", "mdYHis", "mdYhis"]; - if (in_array($format, $fixFormats)) { - $this->fixValue($format, $value); - } - $date = new \DateTime($value); + $date = \DateTime::createFromFormat($this->configuration->get('format'), (string) $value); if ($this->configuration->get('include_time')) { return $date->format('YmdHis'); } @@ -89,33 +84,6 @@ return $value; } - /** - * @param $format - * @param $value - */ - public function fixValue($format, &$value) { - switch ($format) { - case "dmY": - case "mdY": - $value = substr($value,0,2) . "-" . substr($value, 2, 2) . "-" . substr($value,4,4); - break; - case "dmYHis": - case "dmYhis": - case "mdYHis": - case "mdYhis": - $value = substr($value,0,2) . "-" . substr($value, 2, 2) . "-" - . substr($value,4,4) . " " . substr($value, 8, 2) . ":" - . substr($value, 10, 2) . ":" . substr($value,12,2); - break; - case "m-d-Y": - $dateParts = explode("-", $value); - if (isset($dateParts[1]) && isset($dateParts[2])) { - $value = $dateParts[1] . "-" . $dateParts[0] . "-" . $dateParts[2]; - break; - } - } - } - /** * Denormalize the input value. *