From 9d8133643773912d54fb0c7d86ef04e6acffa8c9 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 25 Feb 2023 02:27:22 +0100 Subject: =?UTF-8?q?lire=20tables,=20modifications=20BDD,=20cr=C3=A9ation?= =?UTF-8?q?=20documents=20et=20enveloppes=20latex,=20suppression=20de=20tr?= =?UTF-8?q?aits.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Dates.php | 87 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 39 deletions(-) (limited to 'src/Dates.php') diff --git a/src/Dates.php b/src/Dates.php index 36b19a8..ff6e318 100644 --- a/src/Dates.php +++ b/src/Dates.php @@ -1,5 +1,8 @@ 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); // pour strtotime() - - $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre - $this->year = $splitedDate[2]; - - if(self::$date_format === 'euro') - { - $this->day = $splitedDate[1]; - $this->month = $splitedDate[0]; - } - else - { - $this->day = $splitedDate[0]; - $this->month = $splitedDate[1]; - } + $input = $this->dashOrSlash($input); // formate pour strtotime() + $this->setDayMonthYear($input); //~ if(checkdate($splitedDate[0], $splitedDate[1], $splitedDate[2])) if(checkdate($this->day, $this->month, $this->year)) @@ -62,33 +78,26 @@ class Dates public function setTimestamp(int $input) { $this->timestamp = $input; - $this->date = $this->timestamp_to_date($input); // timestamp (int) -> date (string) + $this->date = $this->timestampToDate($input); // timestamp (int) -> date (string) } - - public function getDate(): string - { - return($this->date); - } - public function getDay(): string - { - return($this->day); - } - public function getMonth(): string + public function setDayMonthYear(string $input) { - return($this->month); - } - public function getYear(): string - { - return($this->year); - } - - public function getTimestamp(): int - { - return($this->timestamp); + $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre + + if(self::$date_format === 'euro') + { + $this->day = $splitedDate[1]; + $this->month = $splitedDate[0]; + } + else + { + $this->day = $splitedDate[0]; + $this->month = $splitedDate[1]; + } + $this->year = $splitedDate[2]; } - private function dashOrSlash(string $date): string { if(self::$date_format === 'euro') @@ -108,11 +117,11 @@ class Dates } } - private function timestamp_to_date(int $timestamp): string + private function timestampToDate(int $timestamp): string { if(self::$date_format === 'euro') { - return(date("j-m-Y", $timestamp)); + return(date("d-m-Y", $timestamp)); } elseif(self::$date_format === 'usa') { -- cgit v1.2.3