@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 38 | 38 | **/ |
| 39 | 39 | function extraire_date($texte): string { |
| 40 | - // format = 2001-08 |
|
| 41 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | - } |
|
| 44 | - return ''; |
|
| 40 | + // format = 2001-08 |
|
| 41 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | + } |
|
| 44 | + return ''; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
@@ -63,29 +63,29 @@ discard block |
||
| 63 | 63 | * - une chaîne vide si la date est considérée nulle |
| 64 | 64 | **/ |
| 65 | 65 | function normaliser_date($date, $forcer_jour = false): string { |
| 66 | - $date = vider_date($date); |
|
| 67 | - if ($date) { |
|
| 68 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | - $date = date('Y-m-d H:i:s', $date); |
|
| 70 | - } |
|
| 71 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | - } else { |
|
| 75 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | - } else { |
|
| 79 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - if ($forcer_jour) { |
|
| 84 | - $date = str_replace('-00', '-01', $date); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $date; |
|
| 66 | + $date = vider_date($date); |
|
| 67 | + if ($date) { |
|
| 68 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | + $date = date('Y-m-d H:i:s', $date); |
|
| 70 | + } |
|
| 71 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | + } else { |
|
| 75 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | + } else { |
|
| 79 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + if ($forcer_jour) { |
|
| 84 | + $date = str_replace('-00', '-01', $date); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return $date; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -98,23 +98,23 @@ discard block |
||
| 98 | 98 | * - Une chaine vide |
| 99 | 99 | **/ |
| 100 | 100 | function vider_date($letexte, $verif_format_date = false): string { |
| 101 | - $letexte ??= ''; |
|
| 102 | - if ( |
|
| 103 | - !$verif_format_date |
|
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | - ) { |
|
| 107 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | - return ''; |
|
| 112 | - } |
|
| 113 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | - return ''; |
|
| 115 | - } // eviter le bug GMT-1 |
|
| 116 | - } |
|
| 117 | - return $letexte; |
|
| 101 | + $letexte ??= ''; |
|
| 102 | + if ( |
|
| 103 | + !$verif_format_date |
|
| 104 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | + ) { |
|
| 107 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | + return ''; |
|
| 112 | + } |
|
| 113 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | + return ''; |
|
| 115 | + } // eviter le bug GMT-1 |
|
| 116 | + } |
|
| 117 | + return $letexte; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | **/ |
| 131 | 131 | function recup_heure($date): array { |
| 132 | 132 | |
| 133 | - if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | - array_shift($elements); |
|
| 135 | - if (!isset($elements[2])) { |
|
| 136 | - $elements[2] = 0; |
|
| 137 | - } |
|
| 138 | - $heure = $elements; |
|
| 139 | - } else { |
|
| 140 | - $heure = [0, 0, 0]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $heure; |
|
| 133 | + if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | + array_shift($elements); |
|
| 135 | + if (!isset($elements[2])) { |
|
| 136 | + $elements[2] = 0; |
|
| 137 | + } |
|
| 138 | + $heure = $elements; |
|
| 139 | + } else { |
|
| 140 | + $heure = [0, 0, 0]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $heure; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | * @return string heures, sinon 0 |
| 155 | 155 | **/ |
| 156 | 156 | function heures($numdate): string { |
| 157 | - $heures = null; |
|
| 158 | - $date_array = recup_heure($numdate); |
|
| 159 | - if ($date_array) { |
|
| 160 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | - } |
|
| 157 | + $heures = null; |
|
| 158 | + $date_array = recup_heure($numdate); |
|
| 159 | + if ($date_array) { |
|
| 160 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - return $heures; |
|
| 163 | + return $heures; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | * @return string minutes, sinon 0 |
| 175 | 175 | **/ |
| 176 | 176 | function minutes($numdate): string { |
| 177 | - $minutes = null; |
|
| 178 | - $date_array = recup_heure($numdate); |
|
| 179 | - if ($date_array) { |
|
| 180 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | - } |
|
| 177 | + $minutes = null; |
|
| 178 | + $date_array = recup_heure($numdate); |
|
| 179 | + if ($date_array) { |
|
| 180 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $minutes; |
|
| 183 | + return $minutes; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | * @return string secondes, sinon 0 |
| 195 | 195 | **/ |
| 196 | 196 | function secondes($numdate): string { |
| 197 | - $secondes = null; |
|
| 198 | - $date_array = recup_heure($numdate); |
|
| 199 | - if ($date_array) { |
|
| 200 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | - } |
|
| 197 | + $secondes = null; |
|
| 198 | + $date_array = recup_heure($numdate); |
|
| 199 | + if ($date_array) { |
|
| 200 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $secondes; |
|
| 203 | + return $secondes; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | * @return string L'heure formatée dans la langue en cours. |
| 220 | 220 | **/ |
| 221 | 221 | function heures_minutes($numdate, $forme = ''): string { |
| 222 | - if ($forme !== 'abbr') { |
|
| 223 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | - } else { |
|
| 225 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | - } |
|
| 222 | + if ($forme !== 'abbr') { |
|
| 223 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | + } else { |
|
| 225 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | + } |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -248,57 +248,57 @@ discard block |
||
| 248 | 248 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 249 | 249 | **/ |
| 250 | 250 | function recup_date($numdate, $forcer_jour = true): array { |
| 251 | - if (!$numdate) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 254 | - $heures = $minutes = $secondes = 0; |
|
| 255 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | - $jour = $regs[1]; |
|
| 257 | - $mois = $regs[2]; |
|
| 258 | - $annee = $regs[3]; |
|
| 259 | - if ($annee < 90) { |
|
| 260 | - $annee = 2000 + $annee; |
|
| 261 | - } elseif ($annee < 100) { |
|
| 262 | - $annee = 1900 + $annee; |
|
| 263 | - } |
|
| 264 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | - $annee = $regs[1]; |
|
| 267 | - $mois = $regs[2]; |
|
| 268 | - $jour = $regs[3]; |
|
| 269 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | - $annee = $regs[1]; |
|
| 272 | - $mois = $regs[2]; |
|
| 273 | - $jour = ''; |
|
| 274 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | - $annee = $regs[1]; |
|
| 277 | - $mois = $regs[2]; |
|
| 278 | - $jour = $regs[3]; |
|
| 279 | - $heures = $regs[4]; |
|
| 280 | - $minutes = $regs[5]; |
|
| 281 | - $secondes = $regs[6]; |
|
| 282 | - } else { |
|
| 283 | - $annee = $mois = $jour = ''; |
|
| 284 | - } |
|
| 285 | - if ($annee > 4000) { |
|
| 286 | - $annee -= 9000; |
|
| 287 | - } |
|
| 288 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | - $jour = substr($jour, 1); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($forcer_jour and $jour == '0') { |
|
| 293 | - $jour = '1'; |
|
| 294 | - } |
|
| 295 | - if ($forcer_jour and $mois == '0') { |
|
| 296 | - $mois = '1'; |
|
| 297 | - } |
|
| 298 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | - } |
|
| 301 | - return []; |
|
| 251 | + if (!$numdate) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | + $heures = $minutes = $secondes = 0; |
|
| 255 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | + $jour = $regs[1]; |
|
| 257 | + $mois = $regs[2]; |
|
| 258 | + $annee = $regs[3]; |
|
| 259 | + if ($annee < 90) { |
|
| 260 | + $annee = 2000 + $annee; |
|
| 261 | + } elseif ($annee < 100) { |
|
| 262 | + $annee = 1900 + $annee; |
|
| 263 | + } |
|
| 264 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | + $annee = $regs[1]; |
|
| 267 | + $mois = $regs[2]; |
|
| 268 | + $jour = $regs[3]; |
|
| 269 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | + $annee = $regs[1]; |
|
| 272 | + $mois = $regs[2]; |
|
| 273 | + $jour = ''; |
|
| 274 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | + $annee = $regs[1]; |
|
| 277 | + $mois = $regs[2]; |
|
| 278 | + $jour = $regs[3]; |
|
| 279 | + $heures = $regs[4]; |
|
| 280 | + $minutes = $regs[5]; |
|
| 281 | + $secondes = $regs[6]; |
|
| 282 | + } else { |
|
| 283 | + $annee = $mois = $jour = ''; |
|
| 284 | + } |
|
| 285 | + if ($annee > 4000) { |
|
| 286 | + $annee -= 9000; |
|
| 287 | + } |
|
| 288 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | + $jour = substr($jour, 1); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($forcer_jour and $jour == '0') { |
|
| 293 | + $jour = '1'; |
|
| 294 | + } |
|
| 295 | + if ($forcer_jour and $mois == '0') { |
|
| 296 | + $mois = '1'; |
|
| 297 | + } |
|
| 298 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | + } |
|
| 301 | + return []; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | * La date relative ou complète |
| 326 | 326 | **/ |
| 327 | 327 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 328 | - return sinon( |
|
| 329 | - date_relative($date, $decalage_maxi), |
|
| 330 | - affdate_heure($date) |
|
| 331 | - ); |
|
| 328 | + return sinon( |
|
| 329 | + date_relative($date, $decalage_maxi), |
|
| 330 | + affdate_heure($date) |
|
| 331 | + ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -361,86 +361,86 @@ discard block |
||
| 361 | 361 | **/ |
| 362 | 362 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 363 | 363 | |
| 364 | - if (!$date) { |
|
| 365 | - return ''; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - if (is_null($ref_date)) { |
|
| 369 | - $ref_time = time(); |
|
| 370 | - } else { |
|
| 371 | - $ref_time = strtotime($ref_date); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | - |
|
| 376 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | - return ''; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($decal < 0) { |
|
| 381 | - $il_y_a = 'date_dans'; |
|
| 382 | - $decal = -1 * $decal; |
|
| 383 | - } else { |
|
| 384 | - $il_y_a = 'date_il_y_a'; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | - return affdate_court($date); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if ($decal > 3600 * 24 * 30) { |
|
| 392 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | - if ($mois < 2) { |
|
| 394 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | - } else { |
|
| 396 | - $delai = "$mois " . _T('date_mois'); |
|
| 397 | - } |
|
| 398 | - } else { |
|
| 399 | - if ($decal > 3600 * 24 * 7) { |
|
| 400 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | - if ($semaines < 2) { |
|
| 402 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | - } else { |
|
| 404 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | - } |
|
| 406 | - } else { |
|
| 407 | - if ($decal > 3600 * 24) { |
|
| 408 | - $jours = floor($decal / (3600 * 24)); |
|
| 409 | - if ($jours < 2) { |
|
| 410 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | - } else { |
|
| 412 | - $delai = "$jours " . _T('date_jours'); |
|
| 413 | - } |
|
| 414 | - } else { |
|
| 415 | - if ($decal >= 3600) { |
|
| 416 | - $heures = floor($decal / 3600); |
|
| 417 | - if ($heures < 2) { |
|
| 418 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | - } else { |
|
| 420 | - $delai = "$heures " . _T('date_heures'); |
|
| 421 | - } |
|
| 422 | - } else { |
|
| 423 | - if ($decal >= 60) { |
|
| 424 | - $minutes = floor($decal / 60); |
|
| 425 | - if ($minutes < 2) { |
|
| 426 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | - } else { |
|
| 428 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | - } |
|
| 430 | - } else { |
|
| 431 | - $secondes = ceil($decal); |
|
| 432 | - if ($secondes < 2) { |
|
| 433 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | - } else { |
|
| 435 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 364 | + if (!$date) { |
|
| 365 | + return ''; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + if (is_null($ref_date)) { |
|
| 369 | + $ref_time = time(); |
|
| 370 | + } else { |
|
| 371 | + $ref_time = strtotime($ref_date); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | + |
|
| 376 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | + return ''; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($decal < 0) { |
|
| 381 | + $il_y_a = 'date_dans'; |
|
| 382 | + $decal = -1 * $decal; |
|
| 383 | + } else { |
|
| 384 | + $il_y_a = 'date_il_y_a'; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | + return affdate_court($date); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if ($decal > 3600 * 24 * 30) { |
|
| 392 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | + if ($mois < 2) { |
|
| 394 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | + } else { |
|
| 396 | + $delai = "$mois " . _T('date_mois'); |
|
| 397 | + } |
|
| 398 | + } else { |
|
| 399 | + if ($decal > 3600 * 24 * 7) { |
|
| 400 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | + if ($semaines < 2) { |
|
| 402 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | + } else { |
|
| 404 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | + } |
|
| 406 | + } else { |
|
| 407 | + if ($decal > 3600 * 24) { |
|
| 408 | + $jours = floor($decal / (3600 * 24)); |
|
| 409 | + if ($jours < 2) { |
|
| 410 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | + } else { |
|
| 412 | + $delai = "$jours " . _T('date_jours'); |
|
| 413 | + } |
|
| 414 | + } else { |
|
| 415 | + if ($decal >= 3600) { |
|
| 416 | + $heures = floor($decal / 3600); |
|
| 417 | + if ($heures < 2) { |
|
| 418 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | + } else { |
|
| 420 | + $delai = "$heures " . _T('date_heures'); |
|
| 421 | + } |
|
| 422 | + } else { |
|
| 423 | + if ($decal >= 60) { |
|
| 424 | + $minutes = floor($decal / 60); |
|
| 425 | + if ($minutes < 2) { |
|
| 426 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | + } else { |
|
| 428 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | + } |
|
| 430 | + } else { |
|
| 431 | + $secondes = ceil($decal); |
|
| 432 | + if ($secondes < 2) { |
|
| 433 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | + } else { |
|
| 435 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -466,32 +466,32 @@ discard block |
||
| 466 | 466 | **/ |
| 467 | 467 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 468 | 468 | |
| 469 | - if (!$date) { |
|
| 470 | - return ''; |
|
| 471 | - } |
|
| 472 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | - |
|
| 474 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if ($decal < -24 * 3600) { |
|
| 479 | - $retour = date_relative($date, $decalage_maxi); |
|
| 480 | - } elseif ($decal < 0) { |
|
| 481 | - $retour = _T('date_demain'); |
|
| 482 | - } else { |
|
| 483 | - if ($decal < (3600 * 24)) { |
|
| 484 | - $retour = _T('date_aujourdhui'); |
|
| 485 | - } else { |
|
| 486 | - if ($decal < (3600 * 24 * 2)) { |
|
| 487 | - $retour = _T('date_hier'); |
|
| 488 | - } else { |
|
| 489 | - $retour = date_relative($date, $decalage_maxi); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $retour; |
|
| 469 | + if (!$date) { |
|
| 470 | + return ''; |
|
| 471 | + } |
|
| 472 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | + |
|
| 474 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($decal < -24 * 3600) { |
|
| 479 | + $retour = date_relative($date, $decalage_maxi); |
|
| 480 | + } elseif ($decal < 0) { |
|
| 481 | + $retour = _T('date_demain'); |
|
| 482 | + } else { |
|
| 483 | + if ($decal < (3600 * 24)) { |
|
| 484 | + $retour = _T('date_aujourdhui'); |
|
| 485 | + } else { |
|
| 486 | + if ($decal < (3600 * 24 * 2)) { |
|
| 487 | + $retour = _T('date_hier'); |
|
| 488 | + } else { |
|
| 489 | + $retour = date_relative($date, $decalage_maxi); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $retour; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -508,174 +508,174 @@ discard block |
||
| 508 | 508 | * @return string |
| 509 | 509 | */ |
| 510 | 510 | function affdate_base($numdate, $vue, $options = []): string { |
| 511 | - if (is_string($options)) { |
|
| 512 | - $options = ['param' => $options]; |
|
| 513 | - } |
|
| 514 | - $date_array = recup_date($numdate, false); |
|
| 515 | - if (!$date_array) { |
|
| 516 | - return ''; |
|
| 517 | - } |
|
| 518 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | - |
|
| 520 | - // 1er, 21st, etc. |
|
| 521 | - $journum = $jour; |
|
| 522 | - |
|
| 523 | - if ($jour == 0) { |
|
| 524 | - $jour = ''; |
|
| 525 | - $njour = 0; |
|
| 526 | - } else { |
|
| 527 | - $njour = intval($jour); |
|
| 528 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | - $jour = $jourth; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $mois = intval($mois); |
|
| 534 | - if ($mois > 0 and $mois < 13) { |
|
| 535 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | - if ($jour) { |
|
| 539 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | - } else { |
|
| 541 | - $jourmois = $nommois; |
|
| 542 | - } |
|
| 543 | - } else { |
|
| 544 | - $nommois = ''; |
|
| 545 | - $jourmois = ''; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($annee < 0) { |
|
| 549 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | - $avjc = true; |
|
| 551 | - } else { |
|
| 552 | - $avjc = false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - switch ($vue) { |
|
| 556 | - case 'saison': |
|
| 557 | - case 'saison_annee': |
|
| 558 | - $saison = ''; |
|
| 559 | - if ($mois > 0) { |
|
| 560 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | - } |
|
| 564 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | - } |
|
| 567 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | - } |
|
| 570 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - if ($vue == 'saison') { |
|
| 575 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | - } else { |
|
| 577 | - return $saison ? trim(_T( |
|
| 578 | - 'date_fmt_saison_annee', |
|
| 579 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | - )) : ''; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - case 'court': |
|
| 584 | - if ($avjc) { |
|
| 585 | - return $annee; |
|
| 586 | - } |
|
| 587 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | - return $annee; |
|
| 590 | - } |
|
| 591 | - if ($annee != $a) { |
|
| 592 | - return _T( |
|
| 593 | - 'date_fmt_mois_annee', |
|
| 594 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return _T( |
|
| 599 | - 'date_fmt_jour_mois', |
|
| 600 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | - ); |
|
| 602 | - |
|
| 603 | - case 'jourcourt': |
|
| 604 | - if ($avjc) { |
|
| 605 | - return $annee; |
|
| 606 | - } |
|
| 607 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | - return $annee; |
|
| 610 | - } |
|
| 611 | - if ($annee != $a) { |
|
| 612 | - return _T( |
|
| 613 | - 'date_fmt_jour_mois_annee', |
|
| 614 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - return _T( |
|
| 619 | - 'date_fmt_jour_mois', |
|
| 620 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - case 'entier': |
|
| 624 | - if ($avjc) { |
|
| 625 | - return $annee; |
|
| 626 | - } |
|
| 627 | - if ($jour) { |
|
| 628 | - return _T( |
|
| 629 | - 'date_fmt_jour_mois_annee', |
|
| 630 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | - ); |
|
| 632 | - } elseif ($mois) { |
|
| 633 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | - } else { |
|
| 635 | - return $annee; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - case 'nom_mois': |
|
| 639 | - return $nommois; |
|
| 640 | - |
|
| 641 | - case 'mois': |
|
| 642 | - return sprintf('%02s', $mois); |
|
| 643 | - |
|
| 644 | - case 'jour': |
|
| 645 | - return $jour; |
|
| 646 | - |
|
| 647 | - case 'journum': |
|
| 648 | - return $journum; |
|
| 649 | - |
|
| 650 | - case 'nom_jour': |
|
| 651 | - if (!$mois or !$njour) { |
|
| 652 | - return ''; |
|
| 653 | - } |
|
| 654 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | - $nom = 1 + (int) date('w', $nom); |
|
| 656 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | - |
|
| 658 | - return _T('date_jour_' . $nom . $param); |
|
| 659 | - |
|
| 660 | - case 'mois_annee': |
|
| 661 | - if ($avjc) { |
|
| 662 | - return $annee; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | - |
|
| 667 | - case 'annee': |
|
| 668 | - return $annee; |
|
| 669 | - |
|
| 670 | - // Cas d'une vue non definie : retomber sur le format |
|
| 671 | - // de date propose par http://www.php.net/date |
|
| 672 | - default: |
|
| 673 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | - $time = strtotime($numdate); |
|
| 676 | - } |
|
| 677 | - return date($vue, $time); |
|
| 678 | - } |
|
| 511 | + if (is_string($options)) { |
|
| 512 | + $options = ['param' => $options]; |
|
| 513 | + } |
|
| 514 | + $date_array = recup_date($numdate, false); |
|
| 515 | + if (!$date_array) { |
|
| 516 | + return ''; |
|
| 517 | + } |
|
| 518 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | + |
|
| 520 | + // 1er, 21st, etc. |
|
| 521 | + $journum = $jour; |
|
| 522 | + |
|
| 523 | + if ($jour == 0) { |
|
| 524 | + $jour = ''; |
|
| 525 | + $njour = 0; |
|
| 526 | + } else { |
|
| 527 | + $njour = intval($jour); |
|
| 528 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | + $jour = $jourth; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $mois = intval($mois); |
|
| 534 | + if ($mois > 0 and $mois < 13) { |
|
| 535 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | + if ($jour) { |
|
| 539 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | + } else { |
|
| 541 | + $jourmois = $nommois; |
|
| 542 | + } |
|
| 543 | + } else { |
|
| 544 | + $nommois = ''; |
|
| 545 | + $jourmois = ''; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ($annee < 0) { |
|
| 549 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | + $avjc = true; |
|
| 551 | + } else { |
|
| 552 | + $avjc = false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + switch ($vue) { |
|
| 556 | + case 'saison': |
|
| 557 | + case 'saison_annee': |
|
| 558 | + $saison = ''; |
|
| 559 | + if ($mois > 0) { |
|
| 560 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | + } |
|
| 564 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | + } |
|
| 567 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | + } |
|
| 570 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + if ($vue == 'saison') { |
|
| 575 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | + } else { |
|
| 577 | + return $saison ? trim(_T( |
|
| 578 | + 'date_fmt_saison_annee', |
|
| 579 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | + )) : ''; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + case 'court': |
|
| 584 | + if ($avjc) { |
|
| 585 | + return $annee; |
|
| 586 | + } |
|
| 587 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | + return $annee; |
|
| 590 | + } |
|
| 591 | + if ($annee != $a) { |
|
| 592 | + return _T( |
|
| 593 | + 'date_fmt_mois_annee', |
|
| 594 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return _T( |
|
| 599 | + 'date_fmt_jour_mois', |
|
| 600 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | + ); |
|
| 602 | + |
|
| 603 | + case 'jourcourt': |
|
| 604 | + if ($avjc) { |
|
| 605 | + return $annee; |
|
| 606 | + } |
|
| 607 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | + return $annee; |
|
| 610 | + } |
|
| 611 | + if ($annee != $a) { |
|
| 612 | + return _T( |
|
| 613 | + 'date_fmt_jour_mois_annee', |
|
| 614 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + return _T( |
|
| 619 | + 'date_fmt_jour_mois', |
|
| 620 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + case 'entier': |
|
| 624 | + if ($avjc) { |
|
| 625 | + return $annee; |
|
| 626 | + } |
|
| 627 | + if ($jour) { |
|
| 628 | + return _T( |
|
| 629 | + 'date_fmt_jour_mois_annee', |
|
| 630 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | + ); |
|
| 632 | + } elseif ($mois) { |
|
| 633 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | + } else { |
|
| 635 | + return $annee; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + case 'nom_mois': |
|
| 639 | + return $nommois; |
|
| 640 | + |
|
| 641 | + case 'mois': |
|
| 642 | + return sprintf('%02s', $mois); |
|
| 643 | + |
|
| 644 | + case 'jour': |
|
| 645 | + return $jour; |
|
| 646 | + |
|
| 647 | + case 'journum': |
|
| 648 | + return $journum; |
|
| 649 | + |
|
| 650 | + case 'nom_jour': |
|
| 651 | + if (!$mois or !$njour) { |
|
| 652 | + return ''; |
|
| 653 | + } |
|
| 654 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | + $nom = 1 + (int) date('w', $nom); |
|
| 656 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | + |
|
| 658 | + return _T('date_jour_' . $nom . $param); |
|
| 659 | + |
|
| 660 | + case 'mois_annee': |
|
| 661 | + if ($avjc) { |
|
| 662 | + return $annee; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | + |
|
| 667 | + case 'annee': |
|
| 668 | + return $annee; |
|
| 669 | + |
|
| 670 | + // Cas d'une vue non definie : retomber sur le format |
|
| 671 | + // de date propose par http://www.php.net/date |
|
| 672 | + default: |
|
| 673 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | + $time = strtotime($numdate); |
|
| 676 | + } |
|
| 677 | + return date($vue, $time); |
|
| 678 | + } |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | * Nom du jour |
| 703 | 703 | **/ |
| 704 | 704 | function nom_jour($numdate, $forme = ''): string { |
| 705 | - if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | - $forme = ''; |
|
| 707 | - } |
|
| 705 | + if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | + $forme = ''; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 709 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * Numéro du jour |
| 729 | 729 | **/ |
| 730 | 730 | function jour($numdate): string { |
| 731 | - return affdate_base($numdate, 'jour'); |
|
| 731 | + return affdate_base($numdate, 'jour'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | * Numéro du jour |
| 747 | 747 | **/ |
| 748 | 748 | function journum($numdate): string { |
| 749 | - return affdate_base($numdate, 'journum'); |
|
| 749 | + return affdate_base($numdate, 'journum'); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | * Numéro du mois (sur 2 chiffres) |
| 765 | 765 | **/ |
| 766 | 766 | function mois($numdate): string { |
| 767 | - return affdate_base($numdate, 'mois'); |
|
| 767 | + return affdate_base($numdate, 'mois'); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * Nom du mois |
| 789 | 789 | **/ |
| 790 | 790 | function nom_mois($numdate, $forme = ''): string { |
| 791 | - if (!($forme === 'abbr')) { |
|
| 792 | - $forme = ''; |
|
| 793 | - } |
|
| 791 | + if (!($forme === 'abbr')) { |
|
| 792 | + $forme = ''; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 795 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * Année (sur 4 chiffres) |
| 811 | 811 | **/ |
| 812 | 812 | function annee($numdate): string { |
| 813 | - return affdate_base($numdate, 'annee'); |
|
| 813 | + return affdate_base($numdate, 'annee'); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -840,11 +840,11 @@ discard block |
||
| 840 | 840 | * La date formatée |
| 841 | 841 | **/ |
| 842 | 842 | function saison($numdate, $hemisphere = 'nord'): string { |
| 843 | - if ($hemisphere !== 'sud') { |
|
| 844 | - $hemisphere = 'nord'; |
|
| 845 | - } |
|
| 843 | + if ($hemisphere !== 'sud') { |
|
| 844 | + $hemisphere = 'nord'; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 847 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -873,11 +873,11 @@ discard block |
||
| 873 | 873 | * La date formatée |
| 874 | 874 | **/ |
| 875 | 875 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 876 | - if ($hemisphere !== 'sud') { |
|
| 877 | - $hemisphere = 'nord'; |
|
| 878 | - } |
|
| 876 | + if ($hemisphere !== 'sud') { |
|
| 877 | + $hemisphere = 'nord'; |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 880 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | /** |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | * La date formatée |
| 906 | 906 | **/ |
| 907 | 907 | function affdate($numdate, $format = 'entier'): string { |
| 908 | - return affdate_base($numdate, $format); |
|
| 908 | + return affdate_base($numdate, $format); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | * La date formatée |
| 933 | 933 | **/ |
| 934 | 934 | function affdate_court($numdate, $annee_courante = null): string { |
| 935 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 935 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * La date formatée |
| 960 | 960 | **/ |
| 961 | 961 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 962 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 962 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * La date formatée |
| 978 | 978 | **/ |
| 979 | 979 | function affdate_mois_annee($numdate): string { |
| 980 | - return affdate_base($numdate, 'mois_annee'); |
|
| 980 | + return affdate_base($numdate, 'mois_annee'); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -995,16 +995,16 @@ discard block |
||
| 995 | 995 | * La date formatée, sinon '' |
| 996 | 996 | **/ |
| 997 | 997 | function affdate_heure($numdate): string { |
| 998 | - $date_array = recup_date($numdate); |
|
| 999 | - if (!$date_array) { |
|
| 1000 | - return ''; |
|
| 1001 | - } |
|
| 1002 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | - |
|
| 1004 | - return _T('date_fmt_jour_heure', [ |
|
| 1005 | - 'jour' => affdate($numdate), |
|
| 1006 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | - ]); |
|
| 998 | + $date_array = recup_date($numdate); |
|
| 999 | + if (!$date_array) { |
|
| 1000 | + return ''; |
|
| 1001 | + } |
|
| 1002 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | + |
|
| 1004 | + return _T('date_fmt_jour_heure', [ |
|
| 1005 | + 'jour' => affdate($numdate), |
|
| 1006 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | + ]); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1036,117 +1036,117 @@ discard block |
||
| 1036 | 1036 | * texte de la date |
| 1037 | 1037 | */ |
| 1038 | 1038 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1039 | - $abbr = $jour = ''; |
|
| 1040 | - $affdate = 'affdate_jourcourt'; |
|
| 1041 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | - $abbr = 'abbr'; |
|
| 1043 | - } |
|
| 1044 | - if (strpos($forme, 'annee') !== false) { |
|
| 1045 | - $affdate = 'affdate'; |
|
| 1046 | - } |
|
| 1047 | - if (strpos($forme, 'jour') !== false) { |
|
| 1048 | - $jour = 'jour'; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | - $dtabbr = '</abbr>'; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - $date_debut = strtotime($date_debut); |
|
| 1059 | - $date_fin = strtotime($date_fin); |
|
| 1060 | - $d = date('Y-m-d', $date_debut); |
|
| 1061 | - $f = date('Y-m-d', $date_fin); |
|
| 1062 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | - |
|
| 1066 | - if ($d == $f) { // meme jour |
|
| 1067 | - $nomjour = nom_jour($d, $abbr); |
|
| 1068 | - $s = $affdate($d); |
|
| 1069 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | - if ($h) { |
|
| 1071 | - if ($hd == $hf) { |
|
| 1072 | - // Lundi 20 fevrier a 18h25 |
|
| 1073 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | - $s = "$dtstart$s$dtabbr"; |
|
| 1075 | - } else { |
|
| 1076 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | - $s = _T( |
|
| 1079 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | - [ |
|
| 1081 | - 'jour' => spip_ucfirst($s), |
|
| 1082 | - 'heure_debut' => $hd, |
|
| 1083 | - 'heure_fin' => $hf, |
|
| 1084 | - 'dtstart' => $dtstart, |
|
| 1085 | - 'dtend' => $dtend, |
|
| 1086 | - 'dtabbr' => $dtabbr |
|
| 1087 | - ], |
|
| 1088 | - [ |
|
| 1089 | - 'sanitize' => false |
|
| 1090 | - ] |
|
| 1091 | - ); |
|
| 1092 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | - else { |
|
| 1094 | - $s = spip_ucfirst(_T( |
|
| 1095 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | - )); |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - } else { |
|
| 1101 | - if ($dtabbr && $dtstart) { |
|
| 1102 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | - } else { |
|
| 1104 | - $s = spip_ucfirst($s); |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - } else { |
|
| 1108 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | - if (!$h) { |
|
| 1110 | - $date_debut = jour($d); |
|
| 1111 | - } else { |
|
| 1112 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | - } |
|
| 1114 | - $date_fin = $affdate($f); |
|
| 1115 | - if ($jour) { |
|
| 1116 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | - } |
|
| 1121 | - if ($h) { |
|
| 1122 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | - } |
|
| 1125 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | - |
|
| 1128 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | - } else { |
|
| 1130 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | - $date_fin = $affdate($f); |
|
| 1132 | - if ($jour) { |
|
| 1133 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | - } |
|
| 1138 | - if ($h) { |
|
| 1139 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - return $s; |
|
| 1039 | + $abbr = $jour = ''; |
|
| 1040 | + $affdate = 'affdate_jourcourt'; |
|
| 1041 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | + $abbr = 'abbr'; |
|
| 1043 | + } |
|
| 1044 | + if (strpos($forme, 'annee') !== false) { |
|
| 1045 | + $affdate = 'affdate'; |
|
| 1046 | + } |
|
| 1047 | + if (strpos($forme, 'jour') !== false) { |
|
| 1048 | + $jour = 'jour'; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | + $dtabbr = '</abbr>'; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + $date_debut = strtotime($date_debut); |
|
| 1059 | + $date_fin = strtotime($date_fin); |
|
| 1060 | + $d = date('Y-m-d', $date_debut); |
|
| 1061 | + $f = date('Y-m-d', $date_fin); |
|
| 1062 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | + |
|
| 1066 | + if ($d == $f) { // meme jour |
|
| 1067 | + $nomjour = nom_jour($d, $abbr); |
|
| 1068 | + $s = $affdate($d); |
|
| 1069 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | + if ($h) { |
|
| 1071 | + if ($hd == $hf) { |
|
| 1072 | + // Lundi 20 fevrier a 18h25 |
|
| 1073 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | + $s = "$dtstart$s$dtabbr"; |
|
| 1075 | + } else { |
|
| 1076 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | + $s = _T( |
|
| 1079 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | + [ |
|
| 1081 | + 'jour' => spip_ucfirst($s), |
|
| 1082 | + 'heure_debut' => $hd, |
|
| 1083 | + 'heure_fin' => $hf, |
|
| 1084 | + 'dtstart' => $dtstart, |
|
| 1085 | + 'dtend' => $dtend, |
|
| 1086 | + 'dtabbr' => $dtabbr |
|
| 1087 | + ], |
|
| 1088 | + [ |
|
| 1089 | + 'sanitize' => false |
|
| 1090 | + ] |
|
| 1091 | + ); |
|
| 1092 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | + else { |
|
| 1094 | + $s = spip_ucfirst(_T( |
|
| 1095 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | + )); |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + } else { |
|
| 1101 | + if ($dtabbr && $dtstart) { |
|
| 1102 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | + } else { |
|
| 1104 | + $s = spip_ucfirst($s); |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + } else { |
|
| 1108 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | + if (!$h) { |
|
| 1110 | + $date_debut = jour($d); |
|
| 1111 | + } else { |
|
| 1112 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | + } |
|
| 1114 | + $date_fin = $affdate($f); |
|
| 1115 | + if ($jour) { |
|
| 1116 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | + } |
|
| 1121 | + if ($h) { |
|
| 1122 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | + } |
|
| 1125 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | + |
|
| 1128 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | + } else { |
|
| 1130 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | + $date_fin = $affdate($f); |
|
| 1132 | + if ($jour) { |
|
| 1133 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | + } |
|
| 1138 | + if ($h) { |
|
| 1139 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + return $s; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1167,10 +1167,10 @@ discard block |
||
| 1167 | 1167 | * Date au format ical |
| 1168 | 1168 | **/ |
| 1169 | 1169 | function date_ical($date, $addminutes = 0): string { |
| 1170 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1170 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1172 | 1172 | |
| 1173 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1173 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -1194,11 +1194,11 @@ discard block |
||
| 1194 | 1194 | * La date formatée |
| 1195 | 1195 | **/ |
| 1196 | 1196 | function date_iso($date_heure): string { |
| 1197 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1197 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1200 | 1200 | |
| 1201 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1201 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | /** |
@@ -1221,11 +1221,11 @@ discard block |
||
| 1221 | 1221 | * La date formatée |
| 1222 | 1222 | **/ |
| 1223 | 1223 | function date_822($date_heure): string { |
| 1224 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1224 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1227 | 1227 | |
| 1228 | - return date('r', $time); |
|
| 1228 | + return date('r', $time); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | * Date au format `Ymd` |
| 1242 | 1242 | **/ |
| 1243 | 1243 | function date_anneemoisjour($d): string { |
| 1244 | - if (!$d) { |
|
| 1245 | - $d = date('Y-m-d'); |
|
| 1246 | - } |
|
| 1244 | + if (!$d) { |
|
| 1245 | + $d = date('Y-m-d'); |
|
| 1246 | + } |
|
| 1247 | 1247 | |
| 1248 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1248 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
@@ -1261,11 +1261,11 @@ discard block |
||
| 1261 | 1261 | * Date au format `Ym` |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function date_anneemois($d): string { |
| 1264 | - if (!$d) { |
|
| 1265 | - $d = date('Y-m-d'); |
|
| 1266 | - } |
|
| 1264 | + if (!$d) { |
|
| 1265 | + $d = date('Y-m-d'); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1268 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | 1271 | /** |
@@ -1281,13 +1281,13 @@ discard block |
||
| 1281 | 1281 | * Date au lundi de la même semaine au format `Ymd` |
| 1282 | 1282 | **/ |
| 1283 | 1283 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1284 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | - if ($w_day == 0) { |
|
| 1286 | - $w_day = 7; |
|
| 1287 | - } // Gaffe: le dimanche est zero |
|
| 1288 | - $debut = $jour - $w_day + 1; |
|
| 1284 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | + if ($w_day == 0) { |
|
| 1286 | + $w_day = 7; |
|
| 1287 | + } // Gaffe: le dimanche est zero |
|
| 1288 | + $debut = $jour - $w_day + 1; |
|
| 1289 | 1289 | |
| 1290 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1290 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | /** |
@@ -1303,11 +1303,11 @@ discard block |
||
| 1303 | 1303 | * Date au dimanche de la même semaine au format `Ymd` |
| 1304 | 1304 | **/ |
| 1305 | 1305 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1306 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | - if ($w_day == 0) { |
|
| 1308 | - $w_day = 7; |
|
| 1309 | - } // Gaffe: le dimanche est zero |
|
| 1310 | - $debut = $jour - $w_day + 1; |
|
| 1306 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | + if ($w_day == 0) { |
|
| 1308 | + $w_day = 7; |
|
| 1309 | + } // Gaffe: le dimanche est zero |
|
| 1310 | + $debut = $jour - $w_day + 1; |
|
| 1311 | 1311 | |
| 1312 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1312 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1313 | 1313 | } |