From 4c470b9306ffb2129befd12948418e80e31888de Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 27 Jun 2016 09:24:22 +0000 Subject: [PATCH] form : add the conversion format for dates git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2765 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- form.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/form.php b/form.php index 78150e2..dc6ddfc 100644 --- a/form.php +++ b/form.php @@ -301,6 +301,24 @@ class form } return $errors; } + + /** Convert Date received in one format to another. + * If the provided string is not corresponding to the format, don't change + * anything. + * Format used http://php.net/manual/en/datetime.createfromformat.php + * @param string $inputDate + * @param string $inputFormat + * @param string $outputFormat + * @return string + */ + public function convertDate ($inputDate, $inputFormat, $outputFormat) + { + $date = DateTime::CreateFromFormat ($inputFormat, $inputDate); + $errors = $date->getLastErrors(); + if ($errors["warning_count"] > 0 || $errors["error_count"] > 0) + return $inputDate; + return $date->format ($outputFormat); + } } /** the definition of a formfield */