Completed
Push — master ( 548e6d...5fac66 )
by cam
01:41
created
ecrire/inc/filtres_dates.php 2 patches
Indentation   +580 added lines, -580 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,14 +130,14 @@  discard block
 block discarded – undo
130 130
  **/
131 131
 function recup_heure($date): array {
132 132
 
133
-	static $d = [0, 0, 0];
134
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
135
-		return $d;
136
-	}
133
+    static $d = [0, 0, 0];
134
+    if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
135
+        return $d;
136
+    }
137 137
 
138
-	array_shift($r);
138
+    array_shift($r);
139 139
 
140
-	return $r;
140
+    return $r;
141 141
 }
142 142
 
143 143
 /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
  * @return string heures, sinon 0
152 152
  **/
153 153
 function heures($numdate): string {
154
-	$heures = null;
155
-	$date_array = recup_heure($numdate);
156
-	if ($date_array) {
157
-		[$heures, $minutes, $secondes] = $date_array;
158
-	}
154
+    $heures = null;
155
+    $date_array = recup_heure($numdate);
156
+    if ($date_array) {
157
+        [$heures, $minutes, $secondes] = $date_array;
158
+    }
159 159
 
160
-	return $heures;
160
+    return $heures;
161 161
 }
162 162
 
163 163
 /**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
  * @return string minutes, sinon 0
172 172
  **/
173 173
 function minutes($numdate): string {
174
-	$minutes = null;
175
-	$date_array = recup_heure($numdate);
176
-	if ($date_array) {
177
-		[$heures, $minutes, $secondes] = $date_array;
178
-	}
174
+    $minutes = null;
175
+    $date_array = recup_heure($numdate);
176
+    if ($date_array) {
177
+        [$heures, $minutes, $secondes] = $date_array;
178
+    }
179 179
 
180
-	return $minutes;
180
+    return $minutes;
181 181
 }
182 182
 
183 183
 /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
  * @return string secondes, sinon 0
192 192
  **/
193 193
 function secondes($numdate): string {
194
-	$secondes = null;
195
-	$date_array = recup_heure($numdate);
196
-	if ($date_array) {
197
-		[$heures, $minutes, $secondes] = $date_array;
198
-	}
194
+    $secondes = null;
195
+    $date_array = recup_heure($numdate);
196
+    if ($date_array) {
197
+        [$heures, $minutes, $secondes] = $date_array;
198
+    }
199 199
 
200
-	return $secondes;
200
+    return $secondes;
201 201
 }
202 202
 
203 203
 /**
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
  * @return string L'heure formatée dans la langue en cours.
217 217
  **/
218 218
 function heures_minutes($numdate, $forme = ''): string {
219
-	if ($forme !== 'abbr') {
220
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
-	} else {
222
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
-	}
219
+    if ($forme !== 'abbr') {
220
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
+    } else {
222
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
+    }
224 224
 }
225 225
 
226 226
 /**
@@ -245,57 +245,57 @@  discard block
 block discarded – undo
245 245
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
246 246
  **/
247 247
 function recup_date($numdate, $forcer_jour = true): array {
248
-	if (!$numdate) {
249
-		return [];
250
-	}
251
-	$heures = $minutes = $secondes = 0;
252
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
253
-		$jour = $regs[1];
254
-		$mois = $regs[2];
255
-		$annee = $regs[3];
256
-		if ($annee < 90) {
257
-			$annee = 2000 + $annee;
258
-		} elseif ($annee < 100) {
259
-			$annee = 1900 + $annee;
260
-		}
261
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
262
-	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
263
-		$annee = $regs[1];
264
-		$mois = $regs[2];
265
-		$jour = $regs[3];
266
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
267
-	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
268
-		$annee = $regs[1];
269
-		$mois = $regs[2];
270
-		$jour = '';
271
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
272
-	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
273
-		$annee = $regs[1];
274
-		$mois = $regs[2];
275
-		$jour = $regs[3];
276
-		$heures = $regs[4];
277
-		$minutes = $regs[5];
278
-		$secondes = $regs[6];
279
-	} else {
280
-		$annee = $mois = $jour = '';
281
-	}
282
-	if ($annee > 4000) {
283
-		$annee -= 9000;
284
-	}
285
-	if (strlen($jour) and substr($jour, 0, 1) == '0') {
286
-		$jour = substr($jour, 1);
287
-	}
288
-
289
-	if ($forcer_jour and $jour == '0') {
290
-		$jour = '1';
291
-	}
292
-	if ($forcer_jour and $mois == '0') {
293
-		$mois = '1';
294
-	}
295
-	if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
296
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
297
-	}
298
-	return [];
248
+    if (!$numdate) {
249
+        return [];
250
+    }
251
+    $heures = $minutes = $secondes = 0;
252
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
253
+        $jour = $regs[1];
254
+        $mois = $regs[2];
255
+        $annee = $regs[3];
256
+        if ($annee < 90) {
257
+            $annee = 2000 + $annee;
258
+        } elseif ($annee < 100) {
259
+            $annee = 1900 + $annee;
260
+        }
261
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
262
+    } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
263
+        $annee = $regs[1];
264
+        $mois = $regs[2];
265
+        $jour = $regs[3];
266
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
267
+    } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
268
+        $annee = $regs[1];
269
+        $mois = $regs[2];
270
+        $jour = '';
271
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
272
+    } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
273
+        $annee = $regs[1];
274
+        $mois = $regs[2];
275
+        $jour = $regs[3];
276
+        $heures = $regs[4];
277
+        $minutes = $regs[5];
278
+        $secondes = $regs[6];
279
+    } else {
280
+        $annee = $mois = $jour = '';
281
+    }
282
+    if ($annee > 4000) {
283
+        $annee -= 9000;
284
+    }
285
+    if (strlen($jour) and substr($jour, 0, 1) == '0') {
286
+        $jour = substr($jour, 1);
287
+    }
288
+
289
+    if ($forcer_jour and $jour == '0') {
290
+        $jour = '1';
291
+    }
292
+    if ($forcer_jour and $mois == '0') {
293
+        $mois = '1';
294
+    }
295
+    if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
296
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
297
+    }
298
+    return [];
299 299
 }
300 300
 
301 301
 /**
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
  *     La date relative ou complète
323 323
  **/
324 324
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
325
-	return sinon(
326
-		date_relative($date, $decalage_maxi),
327
-		affdate_heure($date)
328
-	);
325
+    return sinon(
326
+        date_relative($date, $decalage_maxi),
327
+        affdate_heure($date)
328
+    );
329 329
 }
330 330
 
331 331
 /**
@@ -358,86 +358,86 @@  discard block
 block discarded – undo
358 358
  **/
359 359
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
360 360
 
361
-	if (!$date) {
362
-		return '';
363
-	}
364
-
365
-	if (is_null($ref_date)) {
366
-		$ref_time = time();
367
-	} else {
368
-		$ref_time = strtotime($ref_date);
369
-	}
370
-
371
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
372
-
373
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
374
-		return '';
375
-	}
376
-
377
-	if ($decal < 0) {
378
-		$il_y_a = 'date_dans';
379
-		$decal = -1 * $decal;
380
-	} else {
381
-		$il_y_a = 'date_il_y_a';
382
-	}
383
-
384
-	if ($decal > 3600 * 24 * 30 * 6) {
385
-		return affdate_court($date);
386
-	}
387
-
388
-	if ($decal > 3600 * 24 * 30) {
389
-		$mois = floor($decal / (3600 * 24 * 30));
390
-		if ($mois < 2) {
391
-			$delai = "$mois " . _T('date_un_mois');
392
-		} else {
393
-			$delai = "$mois " . _T('date_mois');
394
-		}
395
-	} else {
396
-		if ($decal > 3600 * 24 * 7) {
397
-			$semaines = floor($decal / (3600 * 24 * 7));
398
-			if ($semaines < 2) {
399
-				$delai = "$semaines " . _T('date_une_semaine');
400
-			} else {
401
-				$delai = "$semaines " . _T('date_semaines');
402
-			}
403
-		} else {
404
-			if ($decal > 3600 * 24) {
405
-				$jours = floor($decal / (3600 * 24));
406
-				if ($jours < 2) {
407
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408
-				} else {
409
-					$delai = "$jours " . _T('date_jours');
410
-				}
411
-			} else {
412
-				if ($decal >= 3600) {
413
-					$heures = floor($decal / 3600);
414
-					if ($heures < 2) {
415
-						$delai = "$heures " . _T('date_une_heure');
416
-					} else {
417
-						$delai = "$heures " . _T('date_heures');
418
-					}
419
-				} else {
420
-					if ($decal >= 60) {
421
-						$minutes = floor($decal / 60);
422
-						if ($minutes < 2) {
423
-							$delai = "$minutes " . _T('date_une_minute');
424
-						} else {
425
-							$delai = "$minutes " . _T('date_minutes');
426
-						}
427
-					} else {
428
-						$secondes = ceil($decal);
429
-						if ($secondes < 2) {
430
-							$delai = "$secondes " . _T('date_une_seconde');
431
-						} else {
432
-							$delai = "$secondes " . _T('date_secondes');
433
-						}
434
-					}
435
-				}
436
-			}
437
-		}
438
-	}
439
-
440
-	return _T($il_y_a, ['delai' => $delai]);
361
+    if (!$date) {
362
+        return '';
363
+    }
364
+
365
+    if (is_null($ref_date)) {
366
+        $ref_time = time();
367
+    } else {
368
+        $ref_time = strtotime($ref_date);
369
+    }
370
+
371
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
372
+
373
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
374
+        return '';
375
+    }
376
+
377
+    if ($decal < 0) {
378
+        $il_y_a = 'date_dans';
379
+        $decal = -1 * $decal;
380
+    } else {
381
+        $il_y_a = 'date_il_y_a';
382
+    }
383
+
384
+    if ($decal > 3600 * 24 * 30 * 6) {
385
+        return affdate_court($date);
386
+    }
387
+
388
+    if ($decal > 3600 * 24 * 30) {
389
+        $mois = floor($decal / (3600 * 24 * 30));
390
+        if ($mois < 2) {
391
+            $delai = "$mois " . _T('date_un_mois');
392
+        } else {
393
+            $delai = "$mois " . _T('date_mois');
394
+        }
395
+    } else {
396
+        if ($decal > 3600 * 24 * 7) {
397
+            $semaines = floor($decal / (3600 * 24 * 7));
398
+            if ($semaines < 2) {
399
+                $delai = "$semaines " . _T('date_une_semaine');
400
+            } else {
401
+                $delai = "$semaines " . _T('date_semaines');
402
+            }
403
+        } else {
404
+            if ($decal > 3600 * 24) {
405
+                $jours = floor($decal / (3600 * 24));
406
+                if ($jours < 2) {
407
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408
+                } else {
409
+                    $delai = "$jours " . _T('date_jours');
410
+                }
411
+            } else {
412
+                if ($decal >= 3600) {
413
+                    $heures = floor($decal / 3600);
414
+                    if ($heures < 2) {
415
+                        $delai = "$heures " . _T('date_une_heure');
416
+                    } else {
417
+                        $delai = "$heures " . _T('date_heures');
418
+                    }
419
+                } else {
420
+                    if ($decal >= 60) {
421
+                        $minutes = floor($decal / 60);
422
+                        if ($minutes < 2) {
423
+                            $delai = "$minutes " . _T('date_une_minute');
424
+                        } else {
425
+                            $delai = "$minutes " . _T('date_minutes');
426
+                        }
427
+                    } else {
428
+                        $secondes = ceil($decal);
429
+                        if ($secondes < 2) {
430
+                            $delai = "$secondes " . _T('date_une_seconde');
431
+                        } else {
432
+                            $delai = "$secondes " . _T('date_secondes');
433
+                        }
434
+                    }
435
+                }
436
+            }
437
+        }
438
+    }
439
+
440
+    return _T($il_y_a, ['delai' => $delai]);
441 441
 }
442 442
 
443 443
 
@@ -463,32 +463,32 @@  discard block
 block discarded – undo
463 463
  **/
464 464
 function date_relativecourt($date, $decalage_maxi = 0): string {
465 465
 
466
-	if (!$date) {
467
-		return '';
468
-	}
469
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
470
-
471
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
472
-		return '';
473
-	}
474
-
475
-	if ($decal < -24 * 3600) {
476
-		$retour = date_relative($date, $decalage_maxi);
477
-	} elseif ($decal < 0) {
478
-		$retour = _T('date_demain');
479
-	} else {
480
-		if ($decal < (3600 * 24)) {
481
-			$retour = _T('date_aujourdhui');
482
-		} else {
483
-			if ($decal < (3600 * 24 * 2)) {
484
-				$retour = _T('date_hier');
485
-			} else {
486
-				$retour = date_relative($date, $decalage_maxi);
487
-			}
488
-		}
489
-	}
490
-
491
-	return $retour;
466
+    if (!$date) {
467
+        return '';
468
+    }
469
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
470
+
471
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
472
+        return '';
473
+    }
474
+
475
+    if ($decal < -24 * 3600) {
476
+        $retour = date_relative($date, $decalage_maxi);
477
+    } elseif ($decal < 0) {
478
+        $retour = _T('date_demain');
479
+    } else {
480
+        if ($decal < (3600 * 24)) {
481
+            $retour = _T('date_aujourdhui');
482
+        } else {
483
+            if ($decal < (3600 * 24 * 2)) {
484
+                $retour = _T('date_hier');
485
+            } else {
486
+                $retour = date_relative($date, $decalage_maxi);
487
+            }
488
+        }
489
+    }
490
+
491
+    return $retour;
492 492
 }
493 493
 
494 494
 /**
@@ -505,174 +505,174 @@  discard block
 block discarded – undo
505 505
  * @return string
506 506
  */
507 507
 function affdate_base($numdate, $vue, $options = []): string {
508
-	if (is_string($options)) {
509
-		$options = ['param' => $options];
510
-	}
511
-	$date_array = recup_date($numdate, false);
512
-	if (!$date_array) {
513
-		return '';
514
-	}
515
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
516
-
517
-	// 1er, 21st, etc.
518
-	$journum = $jour;
519
-
520
-	if ($jour == 0) {
521
-		$jour = '';
522
-		$njour = 0;
523
-	} else {
524
-		$njour = intval($jour);
525
-		if ($jourth = _T('date_jnum' . $jour)) {
526
-			$jour = $jourth;
527
-		}
528
-	}
529
-
530
-	$mois = intval($mois);
531
-	if ($mois > 0 and $mois < 13) {
532
-		/* Traiter le cas "abbr" pour les noms de mois */
533
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
-		$nommois = _T('date_mois_' . $mois . $param);
535
-		if ($jour) {
536
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
537
-		} else {
538
-			$jourmois = $nommois;
539
-		}
540
-	} else {
541
-		$nommois = '';
542
-		$jourmois = '';
543
-	}
544
-
545
-	if ($annee < 0) {
546
-		$annee = -$annee . ' ' . _T('date_avant_jc');
547
-		$avjc = true;
548
-	} else {
549
-		$avjc = false;
550
-	}
551
-
552
-	switch ($vue) {
553
-		case 'saison':
554
-		case 'saison_annee':
555
-			$saison = '';
556
-			if ($mois > 0) {
557
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
558
-				if (($mois == 3 and $jour >= 21) or $mois > 3) {
559
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
560
-				}
561
-				if (($mois == 6 and $jour >= 21) or $mois > 6) {
562
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
563
-				}
564
-				if (($mois == 9 and $jour >= 21) or $mois > 9) {
565
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
566
-				}
567
-				if (($mois == 12 and $jour >= 21) or $mois > 12) {
568
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
569
-				}
570
-			}
571
-			if ($vue == 'saison') {
572
-				return $saison ? _T('date_saison_' . $saison) : '';
573
-			} else {
574
-				return $saison ? trim(_T(
575
-					'date_fmt_saison_annee',
576
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
577
-				)) : '';
578
-			}
579
-
580
-		case 'court':
581
-			if ($avjc) {
582
-				return $annee;
583
-			}
584
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
585
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
586
-				return $annee;
587
-			}
588
-			if ($annee != $a) {
589
-				return _T(
590
-					'date_fmt_mois_annee',
591
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
592
-				);
593
-			}
594
-
595
-			return _T(
596
-				'date_fmt_jour_mois',
597
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
598
-			);
599
-
600
-		case 'jourcourt':
601
-			if ($avjc) {
602
-				return $annee;
603
-			}
604
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
605
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
606
-				return $annee;
607
-			}
608
-			if ($annee != $a) {
609
-				return _T(
610
-					'date_fmt_jour_mois_annee',
611
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
612
-				);
613
-			}
614
-
615
-			return _T(
616
-				'date_fmt_jour_mois',
617
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
618
-			);
619
-
620
-		case 'entier':
621
-			if ($avjc) {
622
-				return $annee;
623
-			}
624
-			if ($jour) {
625
-				return _T(
626
-					'date_fmt_jour_mois_annee',
627
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
628
-				);
629
-			} elseif ($mois) {
630
-				return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
631
-			} else {
632
-				return $annee;
633
-			}
634
-
635
-		case 'nom_mois':
636
-			return $nommois;
637
-
638
-		case 'mois':
639
-			return sprintf('%02s', $mois);
640
-
641
-		case 'jour':
642
-			return $jour;
643
-
644
-		case 'journum':
645
-			return $journum;
646
-
647
-		case 'nom_jour':
648
-			if (!$mois or !$njour) {
649
-				return '';
650
-			}
651
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
652
-			$nom = 1 + (int) date('w', $nom);
653
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
654
-
655
-			return _T('date_jour_' . $nom . $param);
656
-
657
-		case 'mois_annee':
658
-			if ($avjc) {
659
-				return $annee;
660
-			}
661
-
662
-			return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
663
-
664
-		case 'annee':
665
-			return $annee;
666
-
667
-		// Cas d'une vue non definie : retomber sur le format
668
-		// de date propose par http://www.php.net/date
669
-		default:
670
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
671
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
672
-				$time = strtotime($numdate);
673
-			}
674
-			return date($vue, $time);
675
-	}
508
+    if (is_string($options)) {
509
+        $options = ['param' => $options];
510
+    }
511
+    $date_array = recup_date($numdate, false);
512
+    if (!$date_array) {
513
+        return '';
514
+    }
515
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
516
+
517
+    // 1er, 21st, etc.
518
+    $journum = $jour;
519
+
520
+    if ($jour == 0) {
521
+        $jour = '';
522
+        $njour = 0;
523
+    } else {
524
+        $njour = intval($jour);
525
+        if ($jourth = _T('date_jnum' . $jour)) {
526
+            $jour = $jourth;
527
+        }
528
+    }
529
+
530
+    $mois = intval($mois);
531
+    if ($mois > 0 and $mois < 13) {
532
+        /* Traiter le cas "abbr" pour les noms de mois */
533
+        $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
+        $nommois = _T('date_mois_' . $mois . $param);
535
+        if ($jour) {
536
+            $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
537
+        } else {
538
+            $jourmois = $nommois;
539
+        }
540
+    } else {
541
+        $nommois = '';
542
+        $jourmois = '';
543
+    }
544
+
545
+    if ($annee < 0) {
546
+        $annee = -$annee . ' ' . _T('date_avant_jc');
547
+        $avjc = true;
548
+    } else {
549
+        $avjc = false;
550
+    }
551
+
552
+    switch ($vue) {
553
+        case 'saison':
554
+        case 'saison_annee':
555
+            $saison = '';
556
+            if ($mois > 0) {
557
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
558
+                if (($mois == 3 and $jour >= 21) or $mois > 3) {
559
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
560
+                }
561
+                if (($mois == 6 and $jour >= 21) or $mois > 6) {
562
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
563
+                }
564
+                if (($mois == 9 and $jour >= 21) or $mois > 9) {
565
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
566
+                }
567
+                if (($mois == 12 and $jour >= 21) or $mois > 12) {
568
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
569
+                }
570
+            }
571
+            if ($vue == 'saison') {
572
+                return $saison ? _T('date_saison_' . $saison) : '';
573
+            } else {
574
+                return $saison ? trim(_T(
575
+                    'date_fmt_saison_annee',
576
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
577
+                )) : '';
578
+            }
579
+
580
+        case 'court':
581
+            if ($avjc) {
582
+                return $annee;
583
+            }
584
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
585
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
586
+                return $annee;
587
+            }
588
+            if ($annee != $a) {
589
+                return _T(
590
+                    'date_fmt_mois_annee',
591
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
592
+                );
593
+            }
594
+
595
+            return _T(
596
+                'date_fmt_jour_mois',
597
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
598
+            );
599
+
600
+        case 'jourcourt':
601
+            if ($avjc) {
602
+                return $annee;
603
+            }
604
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
605
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
606
+                return $annee;
607
+            }
608
+            if ($annee != $a) {
609
+                return _T(
610
+                    'date_fmt_jour_mois_annee',
611
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
612
+                );
613
+            }
614
+
615
+            return _T(
616
+                'date_fmt_jour_mois',
617
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
618
+            );
619
+
620
+        case 'entier':
621
+            if ($avjc) {
622
+                return $annee;
623
+            }
624
+            if ($jour) {
625
+                return _T(
626
+                    'date_fmt_jour_mois_annee',
627
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
628
+                );
629
+            } elseif ($mois) {
630
+                return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
631
+            } else {
632
+                return $annee;
633
+            }
634
+
635
+        case 'nom_mois':
636
+            return $nommois;
637
+
638
+        case 'mois':
639
+            return sprintf('%02s', $mois);
640
+
641
+        case 'jour':
642
+            return $jour;
643
+
644
+        case 'journum':
645
+            return $journum;
646
+
647
+        case 'nom_jour':
648
+            if (!$mois or !$njour) {
649
+                return '';
650
+            }
651
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
652
+            $nom = 1 + (int) date('w', $nom);
653
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
654
+
655
+            return _T('date_jour_' . $nom . $param);
656
+
657
+        case 'mois_annee':
658
+            if ($avjc) {
659
+                return $annee;
660
+            }
661
+
662
+            return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
663
+
664
+        case 'annee':
665
+            return $annee;
666
+
667
+        // Cas d'une vue non definie : retomber sur le format
668
+        // de date propose par http://www.php.net/date
669
+        default:
670
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
671
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
672
+                $time = strtotime($numdate);
673
+            }
674
+            return date($vue, $time);
675
+    }
676 676
 }
677 677
 
678 678
 
@@ -699,11 +699,11 @@  discard block
 block discarded – undo
699 699
  *     Nom du jour
700 700
  **/
701 701
 function nom_jour($numdate, $forme = ''): string {
702
-	if (!($forme === 'abbr' or $forme === 'initiale')) {
703
-		$forme = '';
704
-	}
702
+    if (!($forme === 'abbr' or $forme === 'initiale')) {
703
+        $forme = '';
704
+    }
705 705
 
706
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
706
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
707 707
 }
708 708
 
709 709
 /**
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
  *     Numéro du jour
726 726
  **/
727 727
 function jour($numdate): string {
728
-	return affdate_base($numdate, 'jour');
728
+    return affdate_base($numdate, 'jour');
729 729
 }
730 730
 
731 731
 /**
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
  *     Numéro du jour
744 744
  **/
745 745
 function journum($numdate): string {
746
-	return affdate_base($numdate, 'journum');
746
+    return affdate_base($numdate, 'journum');
747 747
 }
748 748
 
749 749
 /**
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
  *     Numéro du mois (sur 2 chiffres)
762 762
  **/
763 763
 function mois($numdate): string {
764
-	return  affdate_base($numdate, 'mois');
764
+    return  affdate_base($numdate, 'mois');
765 765
 }
766 766
 
767 767
 /**
@@ -785,11 +785,11 @@  discard block
 block discarded – undo
785 785
  *     Nom du mois
786 786
  **/
787 787
 function nom_mois($numdate, $forme = ''): string {
788
-	if (!($forme === 'abbr')) {
789
-		$forme = '';
790
-	}
788
+    if (!($forme === 'abbr')) {
789
+        $forme = '';
790
+    }
791 791
 
792
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
792
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
793 793
 }
794 794
 
795 795
 /**
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
  *     Année (sur 4 chiffres)
808 808
  **/
809 809
 function annee($numdate): string {
810
-	return affdate_base($numdate, 'annee');
810
+    return affdate_base($numdate, 'annee');
811 811
 }
812 812
 
813 813
 
@@ -837,11 +837,11 @@  discard block
 block discarded – undo
837 837
  *     La date formatée
838 838
  **/
839 839
 function saison($numdate, $hemisphere = 'nord'): string {
840
-	if ($hemisphere !== 'sud') {
841
-		$hemisphere = 'nord';
842
-	}
840
+    if ($hemisphere !== 'sud') {
841
+        $hemisphere = 'nord';
842
+    }
843 843
 
844
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
844
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
845 845
 }
846 846
 
847 847
 
@@ -870,11 +870,11 @@  discard block
 block discarded – undo
870 870
  *     La date formatée
871 871
  **/
872 872
 function saison_annee($numdate, $hemisphere = 'nord'): string {
873
-	if ($hemisphere !== 'sud') {
874
-		$hemisphere = 'nord';
875
-	}
873
+    if ($hemisphere !== 'sud') {
874
+        $hemisphere = 'nord';
875
+    }
876 876
 
877
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
877
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
878 878
 }
879 879
 
880 880
 /**
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
  *     La date formatée
903 903
  **/
904 904
 function affdate($numdate, $format = 'entier'): string {
905
-	return affdate_base($numdate, $format);
905
+    return affdate_base($numdate, $format);
906 906
 }
907 907
 
908 908
 
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
  *     La date formatée
930 930
  **/
931 931
 function affdate_court($numdate, $annee_courante = null): string {
932
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
932
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
933 933
 }
934 934
 
935 935
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *     La date formatée
957 957
  **/
958 958
 function affdate_jourcourt($numdate, $annee_courante = null): string {
959
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
959
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
960 960
 }
961 961
 
962 962
 /**
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
  *     La date formatée
975 975
  **/
976 976
 function affdate_mois_annee($numdate): string {
977
-	return affdate_base($numdate, 'mois_annee');
977
+    return affdate_base($numdate, 'mois_annee');
978 978
 }
979 979
 
980 980
 /**
@@ -992,16 +992,16 @@  discard block
 block discarded – undo
992 992
  *     La date formatée, sinon ''
993 993
  **/
994 994
 function affdate_heure($numdate): string {
995
-	$date_array = recup_date($numdate);
996
-	if (!$date_array) {
997
-		return '';
998
-	}
999
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1000
-
1001
-	return _T('date_fmt_jour_heure', [
1002
-		'jour' => affdate($numdate),
1003
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1004
-	]);
995
+    $date_array = recup_date($numdate);
996
+    if (!$date_array) {
997
+        return '';
998
+    }
999
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1000
+
1001
+    return _T('date_fmt_jour_heure', [
1002
+        'jour' => affdate($numdate),
1003
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1004
+    ]);
1005 1005
 }
1006 1006
 
1007 1007
 /**
@@ -1033,117 +1033,117 @@  discard block
 block discarded – undo
1033 1033
  *     Texte de la date
1034 1034
  */
1035 1035
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
1036
-	$abbr = $jour = '';
1037
-	$affdate = 'affdate_jourcourt';
1038
-	if (strpos($forme, 'abbr') !== false) {
1039
-		$abbr = 'abbr';
1040
-	}
1041
-	if (strpos($forme, 'annee') !== false) {
1042
-		$affdate = 'affdate';
1043
-	}
1044
-	if (strpos($forme, 'jour') !== false) {
1045
-		$jour = 'jour';
1046
-	}
1047
-
1048
-	$dtstart = $dtend = $dtabbr = '';
1049
-	if (strpos($forme, 'hcal') !== false) {
1050
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1052
-		$dtabbr = '</abbr>';
1053
-	}
1054
-
1055
-	$date_debut = strtotime($date_debut);
1056
-	$date_fin = strtotime($date_fin);
1057
-	$d = date('Y-m-d', $date_debut);
1058
-	$f = date('Y-m-d', $date_fin);
1059
-	$h = ($horaire === 'oui' or $horaire === true);
1060
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1061
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1062
-
1063
-	if ($d == $f) { // meme jour
1064
-		$nomjour = nom_jour($d, $abbr);
1065
-		$s = $affdate($d);
1066
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1067
-		if ($h) {
1068
-			if ($hd == $hf) {
1069
-				// Lundi 20 fevrier a 18h25
1070
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1071
-				$s = "$dtstart$s$dtabbr";
1072
-			} else {
1073
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1074
-				if ($dtabbr && $dtstart && $dtend) {
1075
-					$s = _T(
1076
-						'date_fmt_jour_heure_debut_fin_abbr',
1077
-						[
1078
-						'jour' => spip_ucfirst($s),
1079
-						'heure_debut' => $hd,
1080
-						'heure_fin' => $hf,
1081
-						'dtstart' => $dtstart,
1082
-						'dtend' => $dtend,
1083
-						'dtabbr' => $dtabbr
1084
-						],
1085
-						[
1086
-							'sanitize' => false
1087
-						]
1088
-					);
1089
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1090
-				else {
1091
-					$s = spip_ucfirst(_T(
1092
-						'date_fmt_jour_heure_debut_fin',
1093
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1094
-					));
1095
-				}
1096
-			}
1097
-		} else {
1098
-			if ($dtabbr && $dtstart) {
1099
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1100
-			} else {
1101
-				$s = spip_ucfirst($s);
1102
-			}
1103
-		}
1104
-	} else {
1105
-		if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1106
-			if (!$h) {
1107
-				$date_debut = jour($d);
1108
-			} else {
1109
-				$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1110
-			}
1111
-			$date_fin = $affdate($f);
1112
-			if ($jour) {
1113
-				$nomjour_debut = nom_jour($d, $abbr);
1114
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1115
-				$nomjour_fin = nom_jour($f, $abbr);
1116
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1117
-			}
1118
-			if ($h) {
1119
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121
-			}
1122
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1123
-			$date_fin = $dtend . $date_fin . $dtabbr;
1124
-
1125
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126
-		} else {
1127
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1128
-			$date_fin = $affdate($f);
1129
-			if ($jour) {
1130
-				$nomjour_debut = nom_jour($d, $abbr);
1131
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1132
-				$nomjour_fin = nom_jour($f, $abbr);
1133
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1134
-			}
1135
-			if ($h) {
1136
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1137
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138
-			}
1139
-
1140
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1141
-			$date_fin = $dtend . $date_fin . $dtabbr;
1142
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143
-		}
1144
-	}
1145
-
1146
-	return $s;
1036
+    $abbr = $jour = '';
1037
+    $affdate = 'affdate_jourcourt';
1038
+    if (strpos($forme, 'abbr') !== false) {
1039
+        $abbr = 'abbr';
1040
+    }
1041
+    if (strpos($forme, 'annee') !== false) {
1042
+        $affdate = 'affdate';
1043
+    }
1044
+    if (strpos($forme, 'jour') !== false) {
1045
+        $jour = 'jour';
1046
+    }
1047
+
1048
+    $dtstart = $dtend = $dtabbr = '';
1049
+    if (strpos($forme, 'hcal') !== false) {
1050
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1052
+        $dtabbr = '</abbr>';
1053
+    }
1054
+
1055
+    $date_debut = strtotime($date_debut);
1056
+    $date_fin = strtotime($date_fin);
1057
+    $d = date('Y-m-d', $date_debut);
1058
+    $f = date('Y-m-d', $date_fin);
1059
+    $h = ($horaire === 'oui' or $horaire === true);
1060
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1061
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1062
+
1063
+    if ($d == $f) { // meme jour
1064
+        $nomjour = nom_jour($d, $abbr);
1065
+        $s = $affdate($d);
1066
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1067
+        if ($h) {
1068
+            if ($hd == $hf) {
1069
+                // Lundi 20 fevrier a 18h25
1070
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1071
+                $s = "$dtstart$s$dtabbr";
1072
+            } else {
1073
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1074
+                if ($dtabbr && $dtstart && $dtend) {
1075
+                    $s = _T(
1076
+                        'date_fmt_jour_heure_debut_fin_abbr',
1077
+                        [
1078
+                        'jour' => spip_ucfirst($s),
1079
+                        'heure_debut' => $hd,
1080
+                        'heure_fin' => $hf,
1081
+                        'dtstart' => $dtstart,
1082
+                        'dtend' => $dtend,
1083
+                        'dtabbr' => $dtabbr
1084
+                        ],
1085
+                        [
1086
+                            'sanitize' => false
1087
+                        ]
1088
+                    );
1089
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1090
+                else {
1091
+                    $s = spip_ucfirst(_T(
1092
+                        'date_fmt_jour_heure_debut_fin',
1093
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1094
+                    ));
1095
+                }
1096
+            }
1097
+        } else {
1098
+            if ($dtabbr && $dtstart) {
1099
+                $s = $dtstart . spip_ucfirst($s) . $dtabbr;
1100
+            } else {
1101
+                $s = spip_ucfirst($s);
1102
+            }
1103
+        }
1104
+    } else {
1105
+        if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1106
+            if (!$h) {
1107
+                $date_debut = jour($d);
1108
+            } else {
1109
+                $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1110
+            }
1111
+            $date_fin = $affdate($f);
1112
+            if ($jour) {
1113
+                $nomjour_debut = nom_jour($d, $abbr);
1114
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1115
+                $nomjour_fin = nom_jour($f, $abbr);
1116
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1117
+            }
1118
+            if ($h) {
1119
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121
+            }
1122
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1123
+            $date_fin = $dtend . $date_fin . $dtabbr;
1124
+
1125
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126
+        } else {
1127
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1128
+            $date_fin = $affdate($f);
1129
+            if ($jour) {
1130
+                $nomjour_debut = nom_jour($d, $abbr);
1131
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1132
+                $nomjour_fin = nom_jour($f, $abbr);
1133
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1134
+            }
1135
+            if ($h) {
1136
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1137
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138
+            }
1139
+
1140
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1141
+            $date_fin = $dtend . $date_fin . $dtabbr;
1142
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143
+        }
1144
+    }
1145
+
1146
+    return $s;
1147 1147
 }
1148 1148
 
1149 1149
 /**
@@ -1164,10 +1164,10 @@  discard block
 block discarded – undo
1164 1164
  *     Date au format ical
1165 1165
  **/
1166 1166
 function date_ical($date, $addminutes = 0): string {
1167
-	[$heures, $minutes, $secondes] = recup_heure($date);
1168
-	[$annee, $mois, $jour] = recup_date($date);
1167
+    [$heures, $minutes, $secondes] = recup_heure($date);
1168
+    [$annee, $mois, $jour] = recup_date($date);
1169 1169
 
1170
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1170
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1171 1171
 }
1172 1172
 
1173 1173
 
@@ -1191,11 +1191,11 @@  discard block
 block discarded – undo
1191 1191
  *     La date formatée
1192 1192
  **/
1193 1193
 function date_iso($date_heure): string {
1194
-	[$annee, $mois, $jour] = recup_date($date_heure);
1195
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1196
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1194
+    [$annee, $mois, $jour] = recup_date($date_heure);
1195
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1196
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1197 1197
 
1198
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1198
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1199 1199
 }
1200 1200
 
1201 1201
 /**
@@ -1218,11 +1218,11 @@  discard block
 block discarded – undo
1218 1218
  *     La date formatée
1219 1219
  **/
1220 1220
 function date_822($date_heure): string {
1221
-	[$annee, $mois, $jour] = recup_date($date_heure);
1222
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1223
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1221
+    [$annee, $mois, $jour] = recup_date($date_heure);
1222
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1223
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1224 1224
 
1225
-	return date('r', $time);
1225
+    return date('r', $time);
1226 1226
 }
1227 1227
 
1228 1228
 /**
@@ -1238,11 +1238,11 @@  discard block
 block discarded – undo
1238 1238
  *     Date au format `Ymd`
1239 1239
  **/
1240 1240
 function date_anneemoisjour($d): string {
1241
-	if (!$d) {
1242
-		$d = date('Y-m-d');
1243
-	}
1241
+    if (!$d) {
1242
+        $d = date('Y-m-d');
1243
+    }
1244 1244
 
1245
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1245
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1246 1246
 }
1247 1247
 
1248 1248
 /**
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
  *     Date au format `Ym`
1259 1259
  **/
1260 1260
 function date_anneemois($d): string {
1261
-	if (!$d) {
1262
-		$d = date('Y-m-d');
1263
-	}
1261
+    if (!$d) {
1262
+        $d = date('Y-m-d');
1263
+    }
1264 1264
 
1265
-	return substr($d, 0, 4) . substr($d, 5, 2);
1265
+    return substr($d, 0, 4) . substr($d, 5, 2);
1266 1266
 }
1267 1267
 
1268 1268
 /**
@@ -1278,13 +1278,13 @@  discard block
 block discarded – undo
1278 1278
  *     Date au lundi de la même semaine au format `Ymd`
1279 1279
  **/
1280 1280
 function date_debut_semaine($annee, $mois, $jour): string {
1281
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1282
-	if ($w_day == 0) {
1283
-		$w_day = 7;
1284
-	} // Gaffe: le dimanche est zero
1285
-	$debut = $jour - $w_day + 1;
1281
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1282
+    if ($w_day == 0) {
1283
+        $w_day = 7;
1284
+    } // Gaffe: le dimanche est zero
1285
+    $debut = $jour - $w_day + 1;
1286 1286
 
1287
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1287
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1288 1288
 }
1289 1289
 
1290 1290
 /**
@@ -1300,11 +1300,11 @@  discard block
 block discarded – undo
1300 1300
  *     Date au dimanche de la même semaine au format `Ymd`
1301 1301
  **/
1302 1302
 function date_fin_semaine($annee, $mois, $jour): string {
1303
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1304
-	if ($w_day == 0) {
1305
-		$w_day = 7;
1306
-	} // Gaffe: le dimanche est zero
1307
-	$debut = $jour - $w_day + 1;
1303
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1304
+    if ($w_day == 0) {
1305
+        $w_day = 7;
1306
+    } // Gaffe: le dimanche est zero
1307
+    $debut = $jour - $w_day + 1;
1308 1308
 
1309
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1309
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1310 1310
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 function extraire_date($texte): string {
40 40
 	// format = 2001-08
41 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';
42
+		return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01';
43 43
 	}
44 44
 	return '';
45 45
 }
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 		}
71 71
 		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72 72
 			$regs = array_pad($regs, 4, null); // eviter notice php
73
-			$date = $regs[1] . '-00-00' . $regs[3];
73
+			$date = $regs[1].'-00-00'.$regs[3];
74 74
 		} else {
75 75
 			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76 76
 				$regs = array_pad($regs, 4, null); // eviter notice php
77
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
77
+				$date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3];
78 78
 			} else {
79 79
 				$date = date('Y-m-d H:i:s', strtotime($date));
80 80
 			}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	$letexte ??= '';
102 102
 	if (
103 103
 		!$verif_format_date
104
-		or (in_array(strlen($letexte), [10,19]) and
104
+		or (in_array(strlen($letexte), [10, 19]) and
105 105
 			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106 106
 	) {
107 107
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
@@ -388,17 +388,17 @@  discard block
 block discarded – undo
388 388
 	if ($decal > 3600 * 24 * 30) {
389 389
 		$mois = floor($decal / (3600 * 24 * 30));
390 390
 		if ($mois < 2) {
391
-			$delai = "$mois " . _T('date_un_mois');
391
+			$delai = "$mois "._T('date_un_mois');
392 392
 		} else {
393
-			$delai = "$mois " . _T('date_mois');
393
+			$delai = "$mois "._T('date_mois');
394 394
 		}
395 395
 	} else {
396 396
 		if ($decal > 3600 * 24 * 7) {
397 397
 			$semaines = floor($decal / (3600 * 24 * 7));
398 398
 			if ($semaines < 2) {
399
-				$delai = "$semaines " . _T('date_une_semaine');
399
+				$delai = "$semaines "._T('date_une_semaine');
400 400
 			} else {
401
-				$delai = "$semaines " . _T('date_semaines');
401
+				$delai = "$semaines "._T('date_semaines');
402 402
 			}
403 403
 		} else {
404 404
 			if ($decal > 3600 * 24) {
@@ -406,30 +406,30 @@  discard block
 block discarded – undo
406 406
 				if ($jours < 2) {
407 407
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408 408
 				} else {
409
-					$delai = "$jours " . _T('date_jours');
409
+					$delai = "$jours "._T('date_jours');
410 410
 				}
411 411
 			} else {
412 412
 				if ($decal >= 3600) {
413 413
 					$heures = floor($decal / 3600);
414 414
 					if ($heures < 2) {
415
-						$delai = "$heures " . _T('date_une_heure');
415
+						$delai = "$heures "._T('date_une_heure');
416 416
 					} else {
417
-						$delai = "$heures " . _T('date_heures');
417
+						$delai = "$heures "._T('date_heures');
418 418
 					}
419 419
 				} else {
420 420
 					if ($decal >= 60) {
421 421
 						$minutes = floor($decal / 60);
422 422
 						if ($minutes < 2) {
423
-							$delai = "$minutes " . _T('date_une_minute');
423
+							$delai = "$minutes "._T('date_une_minute');
424 424
 						} else {
425
-							$delai = "$minutes " . _T('date_minutes');
425
+							$delai = "$minutes "._T('date_minutes');
426 426
 						}
427 427
 					} else {
428 428
 						$secondes = ceil($decal);
429 429
 						if ($secondes < 2) {
430
-							$delai = "$secondes " . _T('date_une_seconde');
430
+							$delai = "$secondes "._T('date_une_seconde');
431 431
 						} else {
432
-							$delai = "$secondes " . _T('date_secondes');
432
+							$delai = "$secondes "._T('date_secondes');
433 433
 						}
434 434
 					}
435 435
 				}
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		$njour = 0;
523 523
 	} else {
524 524
 		$njour = intval($jour);
525
-		if ($jourth = _T('date_jnum' . $jour)) {
525
+		if ($jourth = _T('date_jnum'.$jour)) {
526 526
 			$jour = $jourth;
527 527
 		}
528 528
 	}
@@ -530,10 +530,10 @@  discard block
 block discarded – undo
530 530
 	$mois = intval($mois);
531 531
 	if ($mois > 0 and $mois < 13) {
532 532
 		/* Traiter le cas "abbr" pour les noms de mois */
533
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
-		$nommois = _T('date_mois_' . $mois . $param);
533
+		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : '');
534
+		$nommois = _T('date_mois_'.$mois.$param);
535 535
 		if ($jour) {
536
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
536
+			$jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]);
537 537
 		} else {
538 538
 			$jourmois = $nommois;
539 539
 		}
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 	}
544 544
 
545 545
 	if ($annee < 0) {
546
-		$annee = -$annee . ' ' . _T('date_avant_jc');
546
+		$annee = -$annee.' '._T('date_avant_jc');
547 547
 		$avjc = true;
548 548
 	} else {
549 549
 		$avjc = false;
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
 				}
570 570
 			}
571 571
 			if ($vue == 'saison') {
572
-				return $saison ? _T('date_saison_' . $saison) : '';
572
+				return $saison ? _T('date_saison_'.$saison) : '';
573 573
 			} else {
574 574
 				return $saison ? trim(_T(
575 575
 					'date_fmt_saison_annee',
576
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
576
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
577 577
 				)) : '';
578 578
 			}
579 579
 
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
 			}
651 651
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
652 652
 			$nom = 1 + (int) date('w', $nom);
653
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
653
+			$param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : '');
654 654
 
655
-			return _T('date_jour_' . $nom . $param);
655
+			return _T('date_jour_'.$nom.$param);
656 656
 
657 657
 		case 'mois_annee':
658 658
 			if ($avjc) {
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
 	$dtstart = $dtend = $dtabbr = '';
1049 1049
 	if (strpos($forme, 'hcal') !== false) {
1050
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1050
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1051
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1052 1052
 		$dtabbr = '</abbr>';
1053 1053
 	}
1054 1054
 
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 			}
1097 1097
 		} else {
1098 1098
 			if ($dtabbr && $dtstart) {
1099
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1099
+				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1100 1100
 			} else {
1101 1101
 				$s = spip_ucfirst($s);
1102 1102
 			}
@@ -1119,8 +1119,8 @@  discard block
 block discarded – undo
1119 1119
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120 1120
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121 1121
 			}
1122
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1123
-			$date_fin = $dtend . $date_fin . $dtabbr;
1122
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1123
+			$date_fin = $dtend.$date_fin.$dtabbr;
1124 1124
 
1125 1125
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126 1126
 		} else {
@@ -1137,8 +1137,8 @@  discard block
 block discarded – undo
1137 1137
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138 1138
 			}
1139 1139
 
1140
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1141
-			$date_fin = $dtend . $date_fin . $dtabbr;
1140
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1141
+			$date_fin = $dtend.$date_fin.$dtabbr;
1142 1142
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143 1143
 		}
1144 1144
 	}
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 		$d = date('Y-m-d');
1243 1243
 	}
1244 1244
 
1245
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1245
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1246 1246
 }
1247 1247
 
1248 1248
 /**
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 		$d = date('Y-m-d');
1263 1263
 	}
1264 1264
 
1265
-	return substr($d, 0, 4) . substr($d, 5, 2);
1265
+	return substr($d, 0, 4).substr($d, 5, 2);
1266 1266
 }
1267 1267
 
1268 1268
 /**
Please login to merge, or discard this patch.