1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class Date_Weeks
26: {
27:
28: 29: 30: 31:
32: public $mois;
33:
34: 35: 36: 37:
38: public $jours;
39:
40: 41: 42: 43:
44: private $tabMois;
45:
46: 47: 48: 49:
50: public $ferie;
51:
52: 53: 54: 55:
56: private $annee;
57:
58: 59: 60: 61:
62: private $semaine;
63:
64: 65: 66: 67:
68: private $daysOfWeek;
69:
70: 71: 72: 73: 74:
75: public function __construct($semaine, $annee)
76: {
77: $this->jours = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
78: $this->tabMois = array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
79: $this->ferie = new Date_Ferie($annee);
80: $this->semaine = intval($semaine);
81: $this->annee = intval($annee);
82: }
83:
84: 85: 86: 87: 88:
89: public function getBoundaries()
90: {
91: $dt = new DateTime($this->annee.'W'.$this->semaine);
92:
93: $lundi = (int)$dt->format('U');
94: $dt->modify('Sunday');
95: $dimanche = (int)$dt->format('U');
96:
97: $this->daysOfWeek[0] = $lundi;
98: $this->mois = $this->tabMois[date("m", $this->daysOfWeek[0]) - 1];
99:
100: return array('lundi'=>$lundi,'dimanche'=>$dimanche);
101: }
102:
103: 104: 105: 106: 107: 108:
109: public function computeDays()
110: {
111: if (empty($this->daysOfWeek))
112: throw new BadFunctionCallException('Use getBoundaries() first');
113: for ($i = 1; $i < 7; $i++)
114: $this->daysOfWeek[$i] = $this->daysOfWeek[$i - 1] + 86400;
115:
116: return $this->daysOfWeek;
117: }
118:
119: 120: 121: 122: 123:
124: public function computeNextPrev()
125: {
126: if ($this->semaine == 1)
127: {
128: $anneePrec = $this->annee - 1;
129: $semainePrec = date("W", $this->daysOfWeek[0] - 86400);
130:
131: $anneeSuiv = $this->annee;
132: $semaineSuiv = 2;
133: }
134: else if ($this->semaine == 52)
135: {
136: $anneePrec = $this->annee;
137: $semainePrec = 51;
138:
139: if (date("W", $this->daysOfWeek[6] + 86400) == 53)
140: {
141: $anneeSuiv = $this->annee;
142: $semaineSuiv = 53;
143: }
144: else
145: {
146: $anneeSuiv = $this->annee + 1;
147: $semaineSuiv = 1;
148: }
149: }
150: elseif ($this->semaine == 53)
151: {
152: $anneePrec = $this->annee;
153: $semainePrec = 52;
154: $anneeSuiv = $this->annee + 1;
155: $semaineSuiv = 1;
156: }
157: else
158: {
159: $anneePrec = $anneeSuiv = $this->annee;
160: $semainePrec = $this->semaine - 1;
161: $semaineSuiv = $this->semaine + 1;
162: }
163:
164: return array('annee' => array('next' => $anneeSuiv, 'prev' => $anneePrec),
165: 'semaine' => array('next' => $semaineSuiv, 'prev' => $semainePrec));
166: }
167:
168: 169: 170: 171: 172:
173: public function getMysqlDays()
174: {
175: $total = count($this->daysOfWeek);
176: $mysqlDays = array();
177:
178: for ($i = 0; $i < $total; $i++)
179: $mysqlDays[$i] = date("Y-m-d", $this->daysOfWeek[$i]);
180:
181: return $mysqlDays;
182: }
183:
184: }
185:
186: ?>