From 32843e50aa981f190bdb4fbc9adbeacc06fdf775 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 17 Oct 2026 23:47:31 +0200 Subject: =?UTF-8?q?retypage=20date=20prestations=20en=20string=203,=20clas?= =?UTF-8?q?se=20Dates=20supprim=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Dates.php | 140 ---------------------------------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 src/Dates.php (limited to 'src/Dates.php') diff --git a/src/Dates.php b/src/Dates.php deleted file mode 100644 index d7ed6c7..0000000 --- a/src/Dates.php +++ /dev/null @@ -1,140 +0,0 @@ - dates avant 1970 - - public function __construct($input = NULL) - { - if(gettype($input) === 'string' && $input !== '') // une date est attendue - { - $this->setDate($input); - } - elseif(gettype($input) === 'integer' && $input !== 0) - { - $this->setTimestamp($input); - $this->setDayMonthYear($this->date); - } - } - - - // getters - public function getDate(): string - { - return $this->date; - } - public function getDay(): string - { - return $this->day; - } - public function getMonth(): string - { - return $this->month; - } - public function getYear(): string - { - return $this->year; - } - - public function getTimestamp(): int - { - return $this->timestamp; - } - - - // setters - public function setDate(string $input) - { - $input = $this->dashOrSlash($input); // formate pour strtotime() - $this->setDayMonthYear($input); - - if(checkdate($this->month, $this->day, $this->year)) // checkdate() veut un format américain - { - $this->date = $input; - $this->timestamp = strtotime($input); // 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 'euro' pour Europe et 'usa' pour États-Unis."); - die(); - } - } - - public function setTimestamp(int $input) - { - $this->timestamp = $input; - $this->date = $this->timestampToDate($input); // timestamp (int) -> date (string) - } - - public function setDayMonthYear(string $input) - { - $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre - - if(self::$date_format === 'euro') - { - $this->day = $splitedDate[0]; - $this->month = $splitedDate[1]; - } - elseif(self::$date_format === 'usa') - { - $this->day = $splitedDate[1]; - $this->month = $splitedDate[0]; - } - else - { - echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'"); - die(); // brutal - } - $this->year = $splitedDate[2]; - } - - private function dashOrSlash(string $date): string - { - if(self::$date_format === 'euro') - { - // change jj/mm/aaaa en jj-mm-aaaa - return(preg_replace('#\D#', '-', $date)); // \D = tout sauf chiffre - } - elseif(self::$date_format === 'usa') - { - // 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 'euro' ou 'usa'"); - die(); // brutal - } - } - - private function timestampToDate(int $timestamp): string - { - if(self::$date_format === 'euro') - { - return(date("d-m-Y", $timestamp)); - } - elseif(self::$date_format === 'usa') - { - return(date("m/d/Y", $timestamp)); - } - else - { - echo("Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur 'euro' ou 'usa'"); - die(); // brutal - } - } -} -- cgit v1.2.3