From a00009e49f5c3b7f67de00c523a1b7e7c2d3713c Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 23 Mar 2021 16:43:14 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Erweiterung=20function=20checkDatum()=20um?= =?UTF-8?q?=20G=C3=BCltigkeitspr=C3=BCfung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/datum.class.php | 45 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/include/datum.class.php b/include/datum.class.php index 90ba0066c..6a2bd58d0 100644 --- a/include/datum.class.php +++ b/include/datum.class.php @@ -151,14 +151,51 @@ class datum * Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist * @return true wenn ok, false wenn falsches Format */ + // public function checkDatum($datum) + // { + // if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum) || mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum)) + // return true; + // else + // return false; + // } + + + + /** + * Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist UND ob es sich um ein gültiges Datum handelt + * @return true wenn ok, false wenn falsches Format und/oder nicht gültig + */ public function checkDatum($datum) - { - if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum) || mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum)) - return true; - else + { + //Format 12.03.2004 + if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum)) + { + + $year=substr($datum,6,4); + $month=substr($datum,3,2); + $day=substr($datum, 0,2); + + } + + //Format 2012-12-04 + elseif(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum)) + { + + $year=substr($datum,0,4); + $month=substr($datum,5,2); + $day=substr($datum,8,2); + } + else + { return false; + } + + return checkdate($month, $day, $year); + } + + /** * Zieht ein Datum von einem anderen ab, und gibt die differenz in Tagen zurueck (mit Vorzeichen) * @param $datum1 From 3359e2e9724da365d69f453f6d4a54f097f620b0 Mon Sep 17 00:00:00 2001 From: manu Date: Thu, 25 Mar 2021 15:45:09 +0100 Subject: [PATCH 2/2] Funktion checkDatum() aktualisiert --- include/datum.class.php | 43 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/include/datum.class.php b/include/datum.class.php index 6a2bd58d0..9b7ebcc5e 100644 --- a/include/datum.class.php +++ b/include/datum.class.php @@ -147,51 +147,34 @@ class datum return false; } - /** - * Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist - * @return true wenn ok, false wenn falsches Format - */ - // public function checkDatum($datum) - // { - // if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum) || mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum)) - // return true; - // else - // return false; - // } - - - /** * Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist UND ob es sich um ein gültiges Datum handelt * @return true wenn ok, false wenn falsches Format und/oder nicht gültig */ public function checkDatum($datum) - { - //Format 12.03.2004 - if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum)) + { + //Format dd.mm.yyyy + if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$", $datum)) { - $year=substr($datum,6,4); - $month=substr($datum,3,2); - $day=substr($datum, 0,2); - + $year = substr($datum, 6, 4); + $month = substr($datum, 3, 2); + $day = substr($datum, 0, 2); } - //Format 2012-12-04 - elseif(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum)) + //Format yyyy-mm-dd + elseif(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$", $datum)) { - - $year=substr($datum,0,4); - $month=substr($datum,5,2); - $day=substr($datum,8,2); + $year = substr($datum, 0, 4); + $month = substr($datum, 5, 2); + $day = substr($datum, 8, 2); } - else + else { return false; } - return checkdate($month, $day, $year); - + return checkdate($month, $day, $year); }