From a45a3e0345890b9df3c5fa7c82966a64491eca02 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 14 Dec 2022 12:52:11 +0100 Subject: MODEL + reorganisation --- php/Dates.php | 105 ---------------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 php/Dates.php (limited to 'php/Dates.php') diff --git a/php/Dates.php b/php/Dates.php deleted file mode 100644 index 264166f..0000000 --- a/php/Dates.php +++ /dev/null @@ -1,105 +0,0 @@ - dates avant 1970 - static public $date_format = 'EU'; // dates européennes jj-mm-aaaa (EU) ou américaines mm/dd/yyyy (US) - - - public function __construct($entry) - { - if(gettype($entry) === 'string') // une date est attendue - { - $this->setDate($entry); - } - elseif(gettype($entry) === 'integer') - { - $this->setTimestamp($entry); - } - } - - - public function setDate(string $entry) - { - $entry = $this->dashOrSlash($entry); // pour strtotime() - - $splitedDate = preg_split('#\D#', $entry); // \D = tout sauf chiffre - - if(self::$date_format === 'EU') - { - $tmp = $splitedDate[0]; - $splitedDate[0] = $splitedDate[1]; - $splitedDate[1] = $tmp; - } - - if(checkdate($splitedDate[0], $splitedDate[1], $splitedDate[2])) - { - $this->date = $entry; - $this->timestamp = strtotime($entry); // date (string) -> timestamp (int) - // strtotime() devine le format en analysant la chaîne en entrée, on l'aide un peu - // avec des /, php considère que la date est américaine - // avec des - ou des ., php considère que la date est européenne - } - else - { - echo("Date incorrecte, le format de la date dans le fichier config.php est " . self::$date_format . ".\nLes choix possibles sont EU pour Europe et US pour États-Unis."); - die(); - } - } - - public function setTimestamp(int $entry) - { - $this->timestamp = $entry; - $this->date = $this->timestamp_to_date($entry); // timestamp (int) -> date (string) - } - - - public function getDate(): string - { - return($this->date); - } - - public function getTimestamp(): int - { - return($this->timestamp); - } - - - private function dashOrSlash(string $date): string - { - if(self::$date_format === 'EU') - { - // change jj/mm/aaaa en jj-mm-aaaa - return(preg_replace('#\D#', '-', $date)); // \D = tout sauf chiffre - } - elseif(self::$date_format === 'US') - { - // change mm-dd.yyyy en mm/dd/yyyy - return(preg_replace('#\D#', '/', $date)); - } - else - { - echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); - die(); // brutal - } - } - - private function timestamp_to_date(int $timestamp): string - { - if(self::$date_format === 'EU') - { - return(date("j-m-Y", $timestamp)); - } - elseif(self::$date_format === 'US') - { - return(date("m/d/Y", $timestamp)); - } - else - { - echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); - die(); // brutal - } - } -} -- cgit v1.2.3