From 6b55446d12a5c39d5a4a4584bfabc7507c2f9b74 Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 2 Dec 2022 15:29:02 +0100 Subject: date<->timestamp, ===, renommage, latex --- php/DateTimestamp.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 php/DateTimestamp.php (limited to 'php/DateTimestamp.php') diff --git a/php/DateTimestamp.php b/php/DateTimestamp.php new file mode 100644 index 0000000..ca07b0a --- /dev/null +++ b/php/DateTimestamp.php @@ -0,0 +1,50 @@ + timestamp (int) + private function get_timestamp(): int + { + if(self::$date_format === 'EU') + { + // change jj/mm/aaaa en jj-mm-aaaa + $this->date = preg_replace('#/#', '-', $this->date); + } + elseif(self::$date_format === 'US') + { + // change mm-dd.yyyy en mm/dd/yyyy + $this->date = preg_replace('#[-\.]#', '/', $this->date); + } + else + { + echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); + die(); // brutal + } + return(strtotime($this->date)); + // 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 + } + + // timestamp (int) -> date jj-mm-aaaa (string) + private function get_date(): string + { + if(self::$date_format === 'EU') + { + return(date("j-m-Y", $this->date)); + } + elseif(self::$date_format === 'US') + { + return(date("m/d/Y", $this->date)); + } + 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