summaryrefslogtreecommitdiff
path: root/src/Dates.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2023-02-25 02:27:22 +0100
committerpolo <ordipolo@gmx.fr>2023-02-25 02:27:22 +0100
commit9d8133643773912d54fb0c7d86ef04e6acffa8c9 (patch)
tree8048a9eeded086e9e9c00ce0a68b9454c171d085 /src/Dates.php
parent209c0b93c529356a094d7133a717e8f6ee6d90c6 (diff)
downloadAppliGestionPHP-9d8133643773912d54fb0c7d86ef04e6acffa8c9.zip
lire tables, modifications BDD, création documents et enveloppes latex, suppression de traits.php
Diffstat (limited to 'src/Dates.php')
-rw-r--r--src/Dates.php87
1 files changed, 48 insertions, 39 deletions
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 @@
1<?php 1<?php
2// php/DateTimestamp.php 2// php/DateTimestamp.php
3//
4// attention à strtotime(), php "devine" le format de la date selon qu'elle comporte des slashs / ou des tirets -
5// pour php une date avec des slashs / est américaine, mais si on fait comme ça aussi par ici
3 6
4class Dates 7class Dates
5{ 8{
@@ -21,27 +24,40 @@ class Dates
21 elseif(gettype($input) === 'integer' && $input !== 0) 24 elseif(gettype($input) === 'integer' && $input !== 0)
22 { 25 {
23 $this->setTimestamp($input); 26 $this->setTimestamp($input);
27 $this->setDayMonthYear($this->date);
24 } 28 }
25 } 29 }
26 30
27 31
32 // getters
33 public function getDate(): string
34 {
35 return($this->date);
36 }
37 public function getDay(): string
38 {
39 return($this->day);
40 }
41 public function getMonth(): string
42 {
43 return($this->month);
44 }
45 public function getYear(): string
46 {
47 return($this->year);
48 }
49
50 public function getTimestamp(): int
51 {
52 return($this->timestamp);
53 }
54
55
56 // setters
28 public function setDate(string $input) 57 public function setDate(string $input)
29 { 58 {
30 $input = $this->dashOrSlash($input); // pour strtotime() 59 $input = $this->dashOrSlash($input); // formate pour strtotime()
31 60 $this->setDayMonthYear($input);
32 $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre
33 $this->year = $splitedDate[2];
34
35 if(self::$date_format === 'euro')
36 {
37 $this->day = $splitedDate[1];
38 $this->month = $splitedDate[0];
39 }
40 else
41 {
42 $this->day = $splitedDate[0];
43 $this->month = $splitedDate[1];
44 }
45 61
46 //~ if(checkdate($splitedDate[0], $splitedDate[1], $splitedDate[2])) 62 //~ if(checkdate($splitedDate[0], $splitedDate[1], $splitedDate[2]))
47 if(checkdate($this->day, $this->month, $this->year)) 63 if(checkdate($this->day, $this->month, $this->year))
@@ -62,33 +78,26 @@ class Dates
62 public function setTimestamp(int $input) 78 public function setTimestamp(int $input)
63 { 79 {
64 $this->timestamp = $input; 80 $this->timestamp = $input;
65 $this->date = $this->timestamp_to_date($input); // timestamp (int) -> date (string) 81 $this->date = $this->timestampToDate($input); // timestamp (int) -> date (string)
66 } 82 }
67 83
68 84 public function setDayMonthYear(string $input)
69 public function getDate(): string
70 {
71 return($this->date);
72 }
73 public function getDay(): string
74 {
75 return($this->day);
76 }
77 public function getMonth(): string
78 { 85 {
79 return($this->month); 86 $splitedDate = preg_split('#\D#', $input); // \D = tout sauf chiffre
80 } 87
81 public function getYear(): string 88 if(self::$date_format === 'euro')
82 { 89 {
83 return($this->year); 90 $this->day = $splitedDate[1];
84 } 91 $this->month = $splitedDate[0];
85 92 }
86 public function getTimestamp(): int 93 else
87 { 94 {
88 return($this->timestamp); 95 $this->day = $splitedDate[0];
96 $this->month = $splitedDate[1];
97 }
98 $this->year = $splitedDate[2];
89 } 99 }
90 100
91
92 private function dashOrSlash(string $date): string 101 private function dashOrSlash(string $date): string
93 { 102 {
94 if(self::$date_format === 'euro') 103 if(self::$date_format === 'euro')
@@ -108,11 +117,11 @@ class Dates
108 } 117 }
109 } 118 }
110 119
111 private function timestamp_to_date(int $timestamp): string 120 private function timestampToDate(int $timestamp): string
112 { 121 {
113 if(self::$date_format === 'euro') 122 if(self::$date_format === 'euro')
114 { 123 {
115 return(date("j-m-Y", $timestamp)); 124 return(date("d-m-Y", $timestamp));
116 } 125 }
117 elseif(self::$date_format === 'usa') 126 elseif(self::$date_format === 'usa')
118 { 127 {