Completed
Push — master ( 70e362...64b936 )
by cam
04:14
created
ecrire/inc/filtres_dates.php 3 patches
Indentation   +557 added lines, -557 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
 
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
  *    Date au format SQL tel que `2008-04-01`
37 37
  **/
38 38
 function extraire_date($texte) {
39
-	// format = 2001-08
40
-	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),", $texte, $regs)) {
41
-		return $regs[1] . "-" . sprintf("%02d", $regs[2]) . "-01";
42
-	}
39
+    // format = 2001-08
40
+    if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),", $texte, $regs)) {
41
+        return $regs[1] . "-" . sprintf("%02d", $regs[2]) . "-01";
42
+    }
43 43
 }
44 44
 
45 45
 
@@ -61,29 +61,29 @@  discard block
 block discarded – undo
61 61
  *     - une chaîne vide si la date est considérée nulle
62 62
  **/
63 63
 function normaliser_date($date, $forcer_jour = false) {
64
-	$date = vider_date($date);
65
-	if ($date) {
66
-		if (preg_match("/^[0-9]{8,10}$/", $date)) {
67
-			$date = date("Y-m-d H:i:s", $date);
68
-		}
69
-		if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
70
-			$regs = array_pad($regs, 4, null); // eviter notice php
71
-			$date = $regs[1] . "-00-00" . $regs[3];
72
-		} else {
73
-			if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
74
-				$regs = array_pad($regs, 4, null); // eviter notice php
75
-				$date = preg_replace("@/@", "-", $regs[1]) . "-00" . $regs[3];
76
-			} else {
77
-				$date = date("Y-m-d H:i:s", strtotime($date));
78
-			}
79
-		}
80
-
81
-		if ($forcer_jour) {
82
-			$date = str_replace('-00', '-01', $date);
83
-		}
84
-	}
85
-
86
-	return $date;
64
+    $date = vider_date($date);
65
+    if ($date) {
66
+        if (preg_match("/^[0-9]{8,10}$/", $date)) {
67
+            $date = date("Y-m-d H:i:s", $date);
68
+        }
69
+        if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
70
+            $regs = array_pad($regs, 4, null); // eviter notice php
71
+            $date = $regs[1] . "-00-00" . $regs[3];
72
+        } else {
73
+            if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
74
+                $regs = array_pad($regs, 4, null); // eviter notice php
75
+                $date = preg_replace("@/@", "-", $regs[1]) . "-00" . $regs[3];
76
+            } else {
77
+                $date = date("Y-m-d H:i:s", strtotime($date));
78
+            }
79
+        }
80
+
81
+        if ($forcer_jour) {
82
+            $date = str_replace('-00', '-01', $date);
83
+        }
84
+    }
85
+
86
+    return $date;
87 87
 }
88 88
 
89 89
 /**
@@ -95,16 +95,16 @@  discard block
 block discarded – undo
95 95
  *     - Une chaine vide
96 96
  **/
97 97
 function vider_date($letexte) {
98
-	if (strncmp("0000-00-00", $letexte, 10) == 0) {
99
-		return '';
100
-	}
101
-	if (strncmp("0001-01-01", $letexte, 10) == 0) {
102
-		return '';
103
-	}
104
-	if (strncmp("1970-01-01", $letexte, 10) == 0) {
105
-		return '';
106
-	}  // eviter le bug GMT-1
107
-	return $letexte;
98
+    if (strncmp("0000-00-00", $letexte, 10) == 0) {
99
+        return '';
100
+    }
101
+    if (strncmp("0001-01-01", $letexte, 10) == 0) {
102
+        return '';
103
+    }
104
+    if (strncmp("1970-01-01", $letexte, 10) == 0) {
105
+        return '';
106
+    }  // eviter le bug GMT-1
107
+    return $letexte;
108 108
 }
109 109
 
110 110
 /**
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
  **/
121 121
 function recup_heure($date) {
122 122
 
123
-	static $d = array(0, 0, 0);
124
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
125
-		return $d;
126
-	}
123
+    static $d = array(0, 0, 0);
124
+    if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
125
+        return $d;
126
+    }
127 127
 
128
-	array_shift($r);
128
+    array_shift($r);
129 129
 
130
-	return $r;
130
+    return $r;
131 131
 }
132 132
 
133 133
 /**
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
  * @return int heures, sinon 0
142 142
  **/
143 143
 function heures($numdate) {
144
-	$date_array = recup_heure($numdate);
145
-	if ($date_array) {
146
-		list($heures, $minutes, $secondes) = $date_array;
147
-	}
144
+    $date_array = recup_heure($numdate);
145
+    if ($date_array) {
146
+        list($heures, $minutes, $secondes) = $date_array;
147
+    }
148 148
 
149
-	return $heures;
149
+    return $heures;
150 150
 }
151 151
 
152 152
 /**
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
  * @return int minutes, sinon 0
161 161
  **/
162 162
 function minutes($numdate) {
163
-	$date_array = recup_heure($numdate);
164
-	if ($date_array) {
165
-		list($heures, $minutes, $secondes) = $date_array;
166
-	}
163
+    $date_array = recup_heure($numdate);
164
+    if ($date_array) {
165
+        list($heures, $minutes, $secondes) = $date_array;
166
+    }
167 167
 
168
-	return $minutes;
168
+    return $minutes;
169 169
 }
170 170
 
171 171
 /**
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
  * @return int secondes, sinon 0
180 180
  **/
181 181
 function secondes($numdate) {
182
-	$date_array = recup_heure($numdate);
183
-	if ($date_array) {
184
-		list($heures, $minutes, $secondes) = $date_array;
185
-	}
182
+    $date_array = recup_heure($numdate);
183
+    if ($date_array) {
184
+        list($heures, $minutes, $secondes) = $date_array;
185
+    }
186 186
 
187
-	return $secondes;
187
+    return $secondes;
188 188
 }
189 189
 
190 190
 /**
@@ -203,12 +203,12 @@  discard block
 block discarded – undo
203 203
  * @return string L'heure formatée dans la langue en cours.
204 204
  **/
205 205
 function heures_minutes($numdate, $forme='') {
206
-	if ($forme !='abbr') {
207
-		return _T('date_fmt_heures_minutes', array('h' => heures($numdate), 'm' => minutes($numdate)));
208
-	}
209
-	else {
210
-		return _T('date_fmt_heures_minutes_court', array('h' => heures($numdate), 'm' => minutes($numdate)));
211
-	}
206
+    if ($forme !='abbr') {
207
+        return _T('date_fmt_heures_minutes', array('h' => heures($numdate), 'm' => minutes($numdate)));
208
+    }
209
+    else {
210
+        return _T('date_fmt_heures_minutes_court', array('h' => heures($numdate), 'm' => minutes($numdate)));
211
+    }
212 212
 }
213 213
 
214 214
 /**
@@ -233,57 +233,57 @@  discard block
 block discarded – undo
233 233
  * @return array [année, mois, jour, heures, minutes, secondes]
234 234
  **/
235 235
 function recup_date($numdate, $forcer_jour = true) {
236
-	if (!$numdate) {
237
-		return '';
238
-	}
239
-	$heures = $minutes = $secondes = 0;
240
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
241
-		$jour = $regs[1];
242
-		$mois = $regs[2];
243
-		$annee = $regs[3];
244
-		if ($annee < 90) {
245
-			$annee = 2000 + $annee;
246
-		} elseif ($annee < 100) {
247
-			$annee = 1900 + $annee;
248
-		}
249
-		list($heures, $minutes, $secondes) = recup_heure($numdate);
250
-
251
-	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
252
-		$annee = $regs[1];
253
-		$mois = $regs[2];
254
-		$jour = $regs[3];
255
-		list($heures, $minutes, $secondes) = recup_heure($numdate);
256
-	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
257
-		$annee = $regs[1];
258
-		$mois = $regs[2];
259
-		$jour = '';
260
-		list($heures, $minutes, $secondes) = recup_heure($numdate);
261
-	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
262
-		$annee = $regs[1];
263
-		$mois = $regs[2];
264
-		$jour = $regs[3];
265
-		$heures = $regs[4];
266
-		$minutes = $regs[5];
267
-		$secondes = $regs[6];
268
-	} else {
269
-		$annee = $mois = $jour = '';
270
-	}
271
-	if ($annee > 4000) {
272
-		$annee -= 9000;
273
-	}
274
-	if (strlen($jour) and substr($jour, 0, 1) == '0') {
275
-		$jour = substr($jour, 1);
276
-	}
277
-
278
-	if ($forcer_jour and $jour == '0') {
279
-		$jour = '1';
280
-	}
281
-	if ($forcer_jour and $mois == '0') {
282
-		$mois = '1';
283
-	}
284
-	if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
285
-		return array($annee, $mois, $jour, $heures, $minutes, $secondes);
286
-	}
236
+    if (!$numdate) {
237
+        return '';
238
+    }
239
+    $heures = $minutes = $secondes = 0;
240
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
241
+        $jour = $regs[1];
242
+        $mois = $regs[2];
243
+        $annee = $regs[3];
244
+        if ($annee < 90) {
245
+            $annee = 2000 + $annee;
246
+        } elseif ($annee < 100) {
247
+            $annee = 1900 + $annee;
248
+        }
249
+        list($heures, $minutes, $secondes) = recup_heure($numdate);
250
+
251
+    } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
252
+        $annee = $regs[1];
253
+        $mois = $regs[2];
254
+        $jour = $regs[3];
255
+        list($heures, $minutes, $secondes) = recup_heure($numdate);
256
+    } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
257
+        $annee = $regs[1];
258
+        $mois = $regs[2];
259
+        $jour = '';
260
+        list($heures, $minutes, $secondes) = recup_heure($numdate);
261
+    } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
262
+        $annee = $regs[1];
263
+        $mois = $regs[2];
264
+        $jour = $regs[3];
265
+        $heures = $regs[4];
266
+        $minutes = $regs[5];
267
+        $secondes = $regs[6];
268
+    } else {
269
+        $annee = $mois = $jour = '';
270
+    }
271
+    if ($annee > 4000) {
272
+        $annee -= 9000;
273
+    }
274
+    if (strlen($jour) and substr($jour, 0, 1) == '0') {
275
+        $jour = substr($jour, 1);
276
+    }
277
+
278
+    if ($forcer_jour and $jour == '0') {
279
+        $jour = '1';
280
+    }
281
+    if ($forcer_jour and $mois == '0') {
282
+        $mois = '1';
283
+    }
284
+    if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
285
+        return array($annee, $mois, $jour, $heures, $minutes, $secondes);
286
+    }
287 287
 }
288 288
 
289 289
 /**
@@ -310,10 +310,10 @@  discard block
 block discarded – undo
310 310
  *     La date relative ou complète
311 311
  **/
312 312
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */) {
313
-	return sinon(
314
-		date_relative($date, $decalage_maxi),
315
-		affdate_heure($date)
316
-	);
313
+    return sinon(
314
+        date_relative($date, $decalage_maxi),
315
+        affdate_heure($date)
316
+    );
317 317
 }
318 318
 
319 319
 /**
@@ -346,85 +346,85 @@  discard block
 block discarded – undo
346 346
  **/
347 347
 function date_relative($date, $decalage_maxi = 0, $ref_date = null) {
348 348
 
349
-	if (is_null($ref_date)) {
350
-		$ref_time = time();
351
-	} else {
352
-		$ref_time = strtotime($ref_date);
353
-	}
354
-
355
-	if (!$date) {
356
-		return;
357
-	}
358
-	$decal = date("U", $ref_time) - date("U", strtotime($date));
359
-
360
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
361
-		return '';
362
-	}
363
-
364
-	if ($decal < 0) {
365
-		$il_y_a = "date_dans";
366
-		$decal = -1 * $decal;
367
-	} else {
368
-		$il_y_a = "date_il_y_a";
369
-	}
370
-
371
-	if ($decal > 3600 * 24 * 30 * 6) {
372
-		return affdate_court($date);
373
-	}
374
-
375
-	if ($decal > 3600 * 24 * 30) {
376
-		$mois = floor($decal / (3600 * 24 * 30));
377
-		if ($mois < 2) {
378
-			$delai = "$mois " . _T("date_un_mois");
379
-		} else {
380
-			$delai = "$mois " . _T("date_mois");
381
-		}
382
-	} else {
383
-		if ($decal > 3600 * 24 * 7) {
384
-			$semaines = floor($decal / (3600 * 24 * 7));
385
-			if ($semaines < 2) {
386
-				$delai = "$semaines " . _T("date_une_semaine");
387
-			} else {
388
-				$delai = "$semaines " . _T("date_semaines");
389
-			}
390
-		} else {
391
-			if ($decal > 3600 * 24) {
392
-				$jours = floor($decal / (3600 * 24));
393
-				if ($jours < 2) {
394
-					return $il_y_a == "date_dans" ? _T("date_demain") : _T("date_hier");
395
-				} else {
396
-					$delai = "$jours " . _T("date_jours");
397
-				}
398
-			} else {
399
-				if ($decal >= 3600) {
400
-					$heures = floor($decal / 3600);
401
-					if ($heures < 2) {
402
-						$delai = "$heures " . _T("date_une_heure");
403
-					} else {
404
-						$delai = "$heures " . _T("date_heures");
405
-					}
406
-				} else {
407
-					if ($decal >= 60) {
408
-						$minutes = floor($decal / 60);
409
-						if ($minutes < 2) {
410
-							$delai = "$minutes " . _T("date_une_minute");
411
-						} else {
412
-							$delai = "$minutes " . _T("date_minutes");
413
-						}
414
-					} else {
415
-						$secondes = ceil($decal);
416
-						if ($secondes < 2) {
417
-							$delai = "$secondes " . _T("date_une_seconde");
418
-						} else {
419
-							$delai = "$secondes " . _T("date_secondes");
420
-						}
421
-					}
422
-				}
423
-			}
424
-		}
425
-	}
426
-
427
-	return _T($il_y_a, array("delai" => $delai));
349
+    if (is_null($ref_date)) {
350
+        $ref_time = time();
351
+    } else {
352
+        $ref_time = strtotime($ref_date);
353
+    }
354
+
355
+    if (!$date) {
356
+        return;
357
+    }
358
+    $decal = date("U", $ref_time) - date("U", strtotime($date));
359
+
360
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
361
+        return '';
362
+    }
363
+
364
+    if ($decal < 0) {
365
+        $il_y_a = "date_dans";
366
+        $decal = -1 * $decal;
367
+    } else {
368
+        $il_y_a = "date_il_y_a";
369
+    }
370
+
371
+    if ($decal > 3600 * 24 * 30 * 6) {
372
+        return affdate_court($date);
373
+    }
374
+
375
+    if ($decal > 3600 * 24 * 30) {
376
+        $mois = floor($decal / (3600 * 24 * 30));
377
+        if ($mois < 2) {
378
+            $delai = "$mois " . _T("date_un_mois");
379
+        } else {
380
+            $delai = "$mois " . _T("date_mois");
381
+        }
382
+    } else {
383
+        if ($decal > 3600 * 24 * 7) {
384
+            $semaines = floor($decal / (3600 * 24 * 7));
385
+            if ($semaines < 2) {
386
+                $delai = "$semaines " . _T("date_une_semaine");
387
+            } else {
388
+                $delai = "$semaines " . _T("date_semaines");
389
+            }
390
+        } else {
391
+            if ($decal > 3600 * 24) {
392
+                $jours = floor($decal / (3600 * 24));
393
+                if ($jours < 2) {
394
+                    return $il_y_a == "date_dans" ? _T("date_demain") : _T("date_hier");
395
+                } else {
396
+                    $delai = "$jours " . _T("date_jours");
397
+                }
398
+            } else {
399
+                if ($decal >= 3600) {
400
+                    $heures = floor($decal / 3600);
401
+                    if ($heures < 2) {
402
+                        $delai = "$heures " . _T("date_une_heure");
403
+                    } else {
404
+                        $delai = "$heures " . _T("date_heures");
405
+                    }
406
+                } else {
407
+                    if ($decal >= 60) {
408
+                        $minutes = floor($decal / 60);
409
+                        if ($minutes < 2) {
410
+                            $delai = "$minutes " . _T("date_une_minute");
411
+                        } else {
412
+                            $delai = "$minutes " . _T("date_minutes");
413
+                        }
414
+                    } else {
415
+                        $secondes = ceil($decal);
416
+                        if ($secondes < 2) {
417
+                            $delai = "$secondes " . _T("date_une_seconde");
418
+                        } else {
419
+                            $delai = "$secondes " . _T("date_secondes");
420
+                        }
421
+                    }
422
+                }
423
+            }
424
+        }
425
+    }
426
+
427
+    return _T($il_y_a, array("delai" => $delai));
428 428
 }
429 429
 
430 430
 
@@ -450,32 +450,32 @@  discard block
 block discarded – undo
450 450
  **/
451 451
 function date_relativecourt($date, $decalage_maxi = 0) {
452 452
 
453
-	if (!$date) {
454
-		return;
455
-	}
456
-	$decal = date("U", strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
457
-
458
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
459
-		return '';
460
-	}
461
-
462
-	if ($decal < -24 * 3600) {
463
-		$retour = date_relative($date, $decalage_maxi);
464
-	} elseif ($decal < 0) {
465
-		$retour = _T("date_demain");
466
-	} else {
467
-		if ($decal < (3600 * 24)) {
468
-			$retour = _T("date_aujourdhui");
469
-		} else {
470
-			if ($decal < (3600 * 24 * 2)) {
471
-				$retour = _T("date_hier");
472
-			} else {
473
-				$retour = date_relative($date, $decalage_maxi);
474
-			}
475
-		}
476
-	}
477
-
478
-	return $retour;
453
+    if (!$date) {
454
+        return;
455
+    }
456
+    $decal = date("U", strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
457
+
458
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
459
+        return '';
460
+    }
461
+
462
+    if ($decal < -24 * 3600) {
463
+        $retour = date_relative($date, $decalage_maxi);
464
+    } elseif ($decal < 0) {
465
+        $retour = _T("date_demain");
466
+    } else {
467
+        if ($decal < (3600 * 24)) {
468
+            $retour = _T("date_aujourdhui");
469
+        } else {
470
+            if ($decal < (3600 * 24 * 2)) {
471
+                $retour = _T("date_hier");
472
+            } else {
473
+                $retour = date_relative($date, $decalage_maxi);
474
+            }
475
+        }
476
+    }
477
+
478
+    return $retour;
479 479
 }
480 480
 
481 481
 /**
@@ -494,165 +494,165 @@  discard block
 block discarded – undo
494 494
  * @return mixed|string
495 495
  */
496 496
 function affdate_base($numdate, $vue, $options = array()) {
497
-	if (is_string($options)) {
498
-		$options = array('param' => $options);
499
-	}
500
-	$date_array = recup_date($numdate, false);
501
-	if (!$date_array) {
502
-		return;
503
-	}
504
-	list($annee, $mois, $jour, $heures, $minutes, $secondes) = $date_array;
505
-
506
-	// 1er, 21st, etc.
507
-	$journum = $jour;
508
-
509
-	if ($jour == 0) {
510
-		$jour = '';
511
-		$njour = 0;
512
-	} else {
513
-		$njour = intval($jour);
514
-		if ($jourth = _T('date_jnum' . $jour)) {
515
-			$jour = $jourth;
516
-		}
517
-	}
518
-
519
-	$mois = intval($mois);
520
-	if ($mois > 0 and $mois < 13) {
521
-		$nommois = _T('date_mois_' . $mois);
522
-		if ($jour) {
523
-			$jourmois = _T('date_de_mois_' . $mois, array('j' => $jour, 'nommois' => $nommois));
524
-		} else {
525
-			$jourmois = $nommois;
526
-		}
527
-	} else {
528
-		$nommois = '';
529
-		$jourmois = '';
530
-	}
531
-
532
-	if ($annee < 0) {
533
-		$annee = -$annee . " " . _T('date_avant_jc');
534
-		$avjc = true;
535
-	} else {
536
-		$avjc = false;
537
-	}
538
-
539
-	switch ($vue) {
540
-		case 'saison':
541
-		case 'saison_annee':
542
-			$saison = '';
543
-			if ($mois > 0) {
544
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
545
-				if (($mois == 3 and $jour >= 21) or $mois > 3) {
546
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
547
-				}
548
-				if (($mois == 6 and $jour >= 21) or $mois > 6) {
549
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
550
-				}
551
-				if (($mois == 9 and $jour >= 21) or $mois > 9) {
552
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
553
-				}
554
-				if (($mois == 12 and $jour >= 21) or $mois > 12) {
555
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
556
-				}
557
-			}
558
-			if ($vue == 'saison') {
559
-				return $saison ? _T('date_saison_' . $saison) : '';
560
-			} else {
561
-				return $saison ? trim(_T('date_fmt_saison_annee',
562
-					array('saison' => _T('date_saison_' . $saison), 'annee' => $annee))) : '';
563
-			}
564
-
565
-		case 'court':
566
-			if ($avjc) {
567
-				return $annee;
568
-			}
569
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
570
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
571
-				return $annee;
572
-			}
573
-			if ($annee != $a) {
574
-				return _T('date_fmt_mois_annee',
575
-					array('mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee));
576
-			}
577
-
578
-			return _T('date_fmt_jour_mois',
579
-				array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
580
-
581
-		case 'jourcourt':
582
-			if ($avjc) {
583
-				return $annee;
584
-			}
585
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
586
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
587
-				return $annee;
588
-			}
589
-			if ($annee != $a) {
590
-				return _T('date_fmt_jour_mois_annee',
591
-					array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
592
-			}
593
-
594
-			return _T('date_fmt_jour_mois',
595
-				array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
596
-
597
-		case 'entier':
598
-			if ($avjc) {
599
-				return $annee;
600
-			}
601
-			if ($jour) {
602
-				return _T('date_fmt_jour_mois_annee',
603
-					array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
604
-			} elseif ($mois) {
605
-				return trim(_T('date_fmt_mois_annee', array('mois' => $mois, 'nommois' => $nommois, 'annee' => $annee)));
606
-			} else {
607
-				return $annee;
608
-			}
609
-
610
-		case 'nom_mois':
611
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
612
-			if ($param and $mois) {
613
-				return _T('date_mois_' . $mois . $param);
614
-			}
615
-
616
-			return $nommois;
617
-
618
-		case 'mois':
619
-			return sprintf("%02s", $mois);
620
-
621
-		case 'jour':
622
-			return $jour;
623
-
624
-		case 'journum':
625
-			return $journum;
626
-
627
-		case 'nom_jour':
628
-			if (!$mois or !$njour) {
629
-				return '';
630
-			}
631
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
632
-			$nom = 1 + date('w', $nom);
633
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
634
-
635
-			return _T('date_jour_' . $nom . $param);
636
-
637
-		case 'mois_annee':
638
-			if ($avjc) {
639
-				return $annee;
640
-			}
641
-
642
-			return trim(_T('date_fmt_mois_annee', array('mois' => $mois, 'nommois' => $nommois, 'annee' => $annee)));
643
-
644
-		case 'annee':
645
-			return $annee;
646
-
647
-		// Cas d'une vue non definie : retomber sur le format
648
-		// de date propose par http://www.php.net/date
649
-		default:
650
-			list($annee, $mois, $jour, $heures, $minutes, $secondes) = $date_array;
651
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee)) {
652
-				$time = strtotime($numdate);
653
-			}
654
-			return date($vue, $time);
655
-	}
497
+    if (is_string($options)) {
498
+        $options = array('param' => $options);
499
+    }
500
+    $date_array = recup_date($numdate, false);
501
+    if (!$date_array) {
502
+        return;
503
+    }
504
+    list($annee, $mois, $jour, $heures, $minutes, $secondes) = $date_array;
505
+
506
+    // 1er, 21st, etc.
507
+    $journum = $jour;
508
+
509
+    if ($jour == 0) {
510
+        $jour = '';
511
+        $njour = 0;
512
+    } else {
513
+        $njour = intval($jour);
514
+        if ($jourth = _T('date_jnum' . $jour)) {
515
+            $jour = $jourth;
516
+        }
517
+    }
518
+
519
+    $mois = intval($mois);
520
+    if ($mois > 0 and $mois < 13) {
521
+        $nommois = _T('date_mois_' . $mois);
522
+        if ($jour) {
523
+            $jourmois = _T('date_de_mois_' . $mois, array('j' => $jour, 'nommois' => $nommois));
524
+        } else {
525
+            $jourmois = $nommois;
526
+        }
527
+    } else {
528
+        $nommois = '';
529
+        $jourmois = '';
530
+    }
531
+
532
+    if ($annee < 0) {
533
+        $annee = -$annee . " " . _T('date_avant_jc');
534
+        $avjc = true;
535
+    } else {
536
+        $avjc = false;
537
+    }
538
+
539
+    switch ($vue) {
540
+        case 'saison':
541
+        case 'saison_annee':
542
+            $saison = '';
543
+            if ($mois > 0) {
544
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
545
+                if (($mois == 3 and $jour >= 21) or $mois > 3) {
546
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
547
+                }
548
+                if (($mois == 6 and $jour >= 21) or $mois > 6) {
549
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
550
+                }
551
+                if (($mois == 9 and $jour >= 21) or $mois > 9) {
552
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
553
+                }
554
+                if (($mois == 12 and $jour >= 21) or $mois > 12) {
555
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
556
+                }
557
+            }
558
+            if ($vue == 'saison') {
559
+                return $saison ? _T('date_saison_' . $saison) : '';
560
+            } else {
561
+                return $saison ? trim(_T('date_fmt_saison_annee',
562
+                    array('saison' => _T('date_saison_' . $saison), 'annee' => $annee))) : '';
563
+            }
564
+
565
+        case 'court':
566
+            if ($avjc) {
567
+                return $annee;
568
+            }
569
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
570
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
571
+                return $annee;
572
+            }
573
+            if ($annee != $a) {
574
+                return _T('date_fmt_mois_annee',
575
+                    array('mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee));
576
+            }
577
+
578
+            return _T('date_fmt_jour_mois',
579
+                array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
580
+
581
+        case 'jourcourt':
582
+            if ($avjc) {
583
+                return $annee;
584
+            }
585
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
586
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
587
+                return $annee;
588
+            }
589
+            if ($annee != $a) {
590
+                return _T('date_fmt_jour_mois_annee',
591
+                    array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
592
+            }
593
+
594
+            return _T('date_fmt_jour_mois',
595
+                array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
596
+
597
+        case 'entier':
598
+            if ($avjc) {
599
+                return $annee;
600
+            }
601
+            if ($jour) {
602
+                return _T('date_fmt_jour_mois_annee',
603
+                    array('jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee));
604
+            } elseif ($mois) {
605
+                return trim(_T('date_fmt_mois_annee', array('mois' => $mois, 'nommois' => $nommois, 'annee' => $annee)));
606
+            } else {
607
+                return $annee;
608
+            }
609
+
610
+        case 'nom_mois':
611
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
612
+            if ($param and $mois) {
613
+                return _T('date_mois_' . $mois . $param);
614
+            }
615
+
616
+            return $nommois;
617
+
618
+        case 'mois':
619
+            return sprintf("%02s", $mois);
620
+
621
+        case 'jour':
622
+            return $jour;
623
+
624
+        case 'journum':
625
+            return $journum;
626
+
627
+        case 'nom_jour':
628
+            if (!$mois or !$njour) {
629
+                return '';
630
+            }
631
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
632
+            $nom = 1 + date('w', $nom);
633
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
634
+
635
+            return _T('date_jour_' . $nom . $param);
636
+
637
+        case 'mois_annee':
638
+            if ($avjc) {
639
+                return $annee;
640
+            }
641
+
642
+            return trim(_T('date_fmt_mois_annee', array('mois' => $mois, 'nommois' => $nommois, 'annee' => $annee)));
643
+
644
+        case 'annee':
645
+            return $annee;
646
+
647
+        // Cas d'une vue non definie : retomber sur le format
648
+        // de date propose par http://www.php.net/date
649
+        default:
650
+            list($annee, $mois, $jour, $heures, $minutes, $secondes) = $date_array;
651
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee)) {
652
+                $time = strtotime($numdate);
653
+            }
654
+            return date($vue, $time);
655
+    }
656 656
 }
657 657
 
658 658
 
@@ -679,11 +679,11 @@  discard block
 block discarded – undo
679 679
  *     Nom du jour
680 680
  **/
681 681
 function nom_jour($numdate, $forme = '') {
682
-	if (!($forme == 'abbr' or $forme == 'initiale')) {
683
-		$forme = '';
684
-	}
682
+    if (!($forme == 'abbr' or $forme == 'initiale')) {
683
+        $forme = '';
684
+    }
685 685
 
686
-	return affdate_base($numdate, 'nom_jour', $forme);
686
+    return affdate_base($numdate, 'nom_jour', $forme);
687 687
 }
688 688
 
689 689
 /**
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
  *     Numéro du jour
706 706
  **/
707 707
 function jour($numdate) {
708
-	return affdate_base($numdate, 'jour');
708
+    return affdate_base($numdate, 'jour');
709 709
 }
710 710
 
711 711
 /**
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
  *     Numéro du jour
724 724
  **/
725 725
 function journum($numdate) {
726
-	return affdate_base($numdate, 'journum');
726
+    return affdate_base($numdate, 'journum');
727 727
 }
728 728
 
729 729
 /**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
  *     Numéro du mois (sur 2 chiffres)
742 742
  **/
743 743
 function mois($numdate) {
744
-	return affdate_base($numdate, 'mois');
744
+    return affdate_base($numdate, 'mois');
745 745
 }
746 746
 
747 747
 /**
@@ -765,11 +765,11 @@  discard block
 block discarded – undo
765 765
  *     Nom du mois
766 766
  **/
767 767
 function nom_mois($numdate, $forme = '') {
768
-	if (!($forme == 'abbr')) {
769
-		$forme = '';
770
-	}
768
+    if (!($forme == 'abbr')) {
769
+        $forme = '';
770
+    }
771 771
 
772
-	return affdate_base($numdate, 'nom_mois', $forme);
772
+    return affdate_base($numdate, 'nom_mois', $forme);
773 773
 }
774 774
 
775 775
 /**
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
  *     Année (sur 4 chiffres)
788 788
  **/
789 789
 function annee($numdate) {
790
-	return affdate_base($numdate, 'annee');
790
+    return affdate_base($numdate, 'annee');
791 791
 }
792 792
 
793 793
 
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
  *     La date formatée
818 818
  **/
819 819
 function saison($numdate, $hemisphere = 'nord') {
820
-	if ($hemisphere != 'sud') {
821
-		$hemisphere = 'nord';
822
-	}
820
+    if ($hemisphere != 'sud') {
821
+        $hemisphere = 'nord';
822
+    }
823 823
 
824
-	return affdate_base($numdate, 'saison', $hemisphere);
824
+    return affdate_base($numdate, 'saison', $hemisphere);
825 825
 }
826 826
 
827 827
 
@@ -850,11 +850,11 @@  discard block
 block discarded – undo
850 850
  *     La date formatée
851 851
  **/
852 852
 function saison_annee($numdate, $hemisphere = 'nord') {
853
-	if ($hemisphere != 'sud') {
854
-		$hemisphere = 'nord';
855
-	}
853
+    if ($hemisphere != 'sud') {
854
+        $hemisphere = 'nord';
855
+    }
856 856
 
857
-	return affdate_base($numdate, 'saison_annee', $hemisphere);
857
+    return affdate_base($numdate, 'saison_annee', $hemisphere);
858 858
 }
859 859
 
860 860
 /**
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
  *     La date formatée
883 883
  **/
884 884
 function affdate($numdate, $format = 'entier') {
885
-	return affdate_base($numdate, $format);
885
+    return affdate_base($numdate, $format);
886 886
 }
887 887
 
888 888
 
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
  *     La date formatée
910 910
  **/
911 911
 function affdate_court($numdate, $annee_courante = null) {
912
-	return affdate_base($numdate, 'court', array('annee_courante' => $annee_courante));
912
+    return affdate_base($numdate, 'court', array('annee_courante' => $annee_courante));
913 913
 }
914 914
 
915 915
 
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
  *     La date formatée
937 937
  **/
938 938
 function affdate_jourcourt($numdate, $annee_courante = null) {
939
-	return affdate_base($numdate, 'jourcourt', array('annee_courante' => $annee_courante));
939
+    return affdate_base($numdate, 'jourcourt', array('annee_courante' => $annee_courante));
940 940
 }
941 941
 
942 942
 /**
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
  *     La date formatée
955 955
  **/
956 956
 function affdate_mois_annee($numdate) {
957
-	return affdate_base($numdate, 'mois_annee');
957
+    return affdate_base($numdate, 'mois_annee');
958 958
 }
959 959
 
960 960
 /**
@@ -972,16 +972,16 @@  discard block
 block discarded – undo
972 972
  *     La date formatée
973 973
  **/
974 974
 function affdate_heure($numdate) {
975
-	$date_array = recup_date($numdate);
976
-	if (!$date_array) {
977
-		return;
978
-	}
979
-	list($annee, $mois, $jour, $heures, $minutes, $sec) = $date_array;
980
-
981
-	return _T('date_fmt_jour_heure', array(
982
-		'jour' => affdate($numdate),
983
-		'heure' => _T('date_fmt_heures_minutes', array('h' => $heures, 'm' => $minutes))
984
-	));
975
+    $date_array = recup_date($numdate);
976
+    if (!$date_array) {
977
+        return;
978
+    }
979
+    list($annee, $mois, $jour, $heures, $minutes, $sec) = $date_array;
980
+
981
+    return _T('date_fmt_jour_heure', array(
982
+        'jour' => affdate($numdate),
983
+        'heure' => _T('date_fmt_heures_minutes', array('h' => $heures, 'm' => $minutes))
984
+    ));
985 985
 }
986 986
 
987 987
 /**
@@ -1013,114 +1013,114 @@  discard block
 block discarded – undo
1013 1013
  *     Texte de la date
1014 1014
  */
1015 1015
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = '') {
1016
-	$abbr = $jour = '';
1017
-	$affdate = "affdate_jourcourt";
1018
-	if (strpos($forme, 'abbr') !== false) {
1019
-		$abbr = 'abbr';
1020
-	}
1021
-	if (strpos($forme, 'annee') !== false) {
1022
-		$affdate = 'affdate';
1023
-	}
1024
-	if (strpos($forme, 'jour') !== false) {
1025
-		$jour = 'jour';
1026
-	}
1027
-
1028
-	$dtstart = $dtend = $dtabbr = "";
1029
-	if (strpos($forme, 'hcal') !== false) {
1030
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1031
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1032
-		$dtabbr = "</abbr>";
1033
-	}
1034
-
1035
-	$date_debut = strtotime($date_debut);
1036
-	$date_fin = strtotime($date_fin);
1037
-	$d = date("Y-m-d", $date_debut);
1038
-	$f = date("Y-m-d", $date_fin);
1039
-	$h = ($horaire === 'oui' or $horaire === true);
1040
-	$hd = _T('date_fmt_heures_minutes_court', array('h' => date("H", $date_debut), 'm' => date("i", $date_debut)));
1041
-	$hf = _T('date_fmt_heures_minutes_court', array('h' => date("H", $date_fin), 'm' => date("i", $date_fin)));
1042
-
1043
-	if ($d == $f) { // meme jour
1044
-		$nomjour = nom_jour($d, $abbr);
1045
-		$s = $affdate($d);
1046
-		$s = _T('date_fmt_jour', array('nomjour' => $nomjour, 'jour' => $s));
1047
-		if ($h) {
1048
-			if ($hd == $hf) {
1049
-				// Lundi 20 fevrier a 18h25
1050
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', array('jour' => $s, 'heure' => $hd)));
1051
-				$s = "$dtstart$s$dtabbr";
1052
-			} else {
1053
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1054
-				if ($dtabbr && $dtstart && $dtend) {
1055
-					$s = _T('date_fmt_jour_heure_debut_fin_abbr', array(
1056
-						'jour' => spip_ucfirst($s),
1057
-						'heure_debut' => $hd,
1058
-						'heure_fin' => $hf,
1059
-						'dtstart' => $dtstart,
1060
-						'dtend' => $dtend,
1061
-						'dtabbr' => $dtabbr
1062
-					),
1063
-						array(
1064
-							'sanitize' => false
1065
-						)
1066
-					);
1067
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1068
-				else {
1069
-					$s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',
1070
-						array('jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf)));
1071
-				}
1072
-			}
1073
-		} else {
1074
-			if ($dtabbr && $dtstart) {
1075
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1076
-			} else {
1077
-				$s = spip_ucfirst($s);
1078
-			}
1079
-		}
1080
-	} else {
1081
-		if ((date("Y-m", $date_debut)) == date("Y-m", $date_fin)) { // meme annee et mois, jours differents
1082
-			if (!$h) {
1083
-				$date_debut = jour($d);
1084
-			} else {
1085
-				$date_debut = affdate_jourcourt($d, date("Y", $date_fin));
1086
-			}
1087
-			$date_fin = $affdate($f);
1088
-			if ($jour) {
1089
-				$nomjour_debut = nom_jour($d, $abbr);
1090
-				$date_debut = _T('date_fmt_jour', array('nomjour' => $nomjour_debut, 'jour' => $date_debut));
1091
-				$nomjour_fin = nom_jour($f, $abbr);
1092
-				$date_fin = _T('date_fmt_jour', array('nomjour' => $nomjour_fin, 'jour' => $date_fin));
1093
-			}
1094
-			if ($h) {
1095
-				$date_debut = _T('date_fmt_jour_heure', array('jour' => $date_debut, 'heure' => $hd));
1096
-				$date_fin = _T('date_fmt_jour_heure', array('jour' => $date_fin, 'heure' => $hf));
1097
-			}
1098
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1099
-			$date_fin = $dtend . $date_fin . $dtabbr;
1100
-
1101
-			$s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin' => $date_fin));
1102
-		} else {
1103
-			$date_debut = affdate_jourcourt($d, date("Y", $date_fin));
1104
-			$date_fin = $affdate($f);
1105
-			if ($jour) {
1106
-				$nomjour_debut = nom_jour($d, $abbr);
1107
-				$date_debut = _T('date_fmt_jour', array('nomjour' => $nomjour_debut, 'jour' => $date_debut));
1108
-				$nomjour_fin = nom_jour($f, $abbr);
1109
-				$date_fin = _T('date_fmt_jour', array('nomjour' => $nomjour_fin, 'jour' => $date_fin));
1110
-			}
1111
-			if ($h) {
1112
-				$date_debut = _T('date_fmt_jour_heure', array('jour' => $date_debut, 'heure' => $hd));
1113
-				$date_fin = _T('date_fmt_jour_heure', array('jour' => $date_fin, 'heure' => $hf));
1114
-			}
1115
-
1116
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1117
-			$date_fin = $dtend . $date_fin . $dtabbr;
1118
-			$s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin' => $date_fin));
1119
-
1120
-		}
1121
-	}
1122
-
1123
-	return $s;
1016
+    $abbr = $jour = '';
1017
+    $affdate = "affdate_jourcourt";
1018
+    if (strpos($forme, 'abbr') !== false) {
1019
+        $abbr = 'abbr';
1020
+    }
1021
+    if (strpos($forme, 'annee') !== false) {
1022
+        $affdate = 'affdate';
1023
+    }
1024
+    if (strpos($forme, 'jour') !== false) {
1025
+        $jour = 'jour';
1026
+    }
1027
+
1028
+    $dtstart = $dtend = $dtabbr = "";
1029
+    if (strpos($forme, 'hcal') !== false) {
1030
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1031
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1032
+        $dtabbr = "</abbr>";
1033
+    }
1034
+
1035
+    $date_debut = strtotime($date_debut);
1036
+    $date_fin = strtotime($date_fin);
1037
+    $d = date("Y-m-d", $date_debut);
1038
+    $f = date("Y-m-d", $date_fin);
1039
+    $h = ($horaire === 'oui' or $horaire === true);
1040
+    $hd = _T('date_fmt_heures_minutes_court', array('h' => date("H", $date_debut), 'm' => date("i", $date_debut)));
1041
+    $hf = _T('date_fmt_heures_minutes_court', array('h' => date("H", $date_fin), 'm' => date("i", $date_fin)));
1042
+
1043
+    if ($d == $f) { // meme jour
1044
+        $nomjour = nom_jour($d, $abbr);
1045
+        $s = $affdate($d);
1046
+        $s = _T('date_fmt_jour', array('nomjour' => $nomjour, 'jour' => $s));
1047
+        if ($h) {
1048
+            if ($hd == $hf) {
1049
+                // Lundi 20 fevrier a 18h25
1050
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', array('jour' => $s, 'heure' => $hd)));
1051
+                $s = "$dtstart$s$dtabbr";
1052
+            } else {
1053
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1054
+                if ($dtabbr && $dtstart && $dtend) {
1055
+                    $s = _T('date_fmt_jour_heure_debut_fin_abbr', array(
1056
+                        'jour' => spip_ucfirst($s),
1057
+                        'heure_debut' => $hd,
1058
+                        'heure_fin' => $hf,
1059
+                        'dtstart' => $dtstart,
1060
+                        'dtend' => $dtend,
1061
+                        'dtabbr' => $dtabbr
1062
+                    ),
1063
+                        array(
1064
+                            'sanitize' => false
1065
+                        )
1066
+                    );
1067
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1068
+                else {
1069
+                    $s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',
1070
+                        array('jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf)));
1071
+                }
1072
+            }
1073
+        } else {
1074
+            if ($dtabbr && $dtstart) {
1075
+                $s = $dtstart . spip_ucfirst($s) . $dtabbr;
1076
+            } else {
1077
+                $s = spip_ucfirst($s);
1078
+            }
1079
+        }
1080
+    } else {
1081
+        if ((date("Y-m", $date_debut)) == date("Y-m", $date_fin)) { // meme annee et mois, jours differents
1082
+            if (!$h) {
1083
+                $date_debut = jour($d);
1084
+            } else {
1085
+                $date_debut = affdate_jourcourt($d, date("Y", $date_fin));
1086
+            }
1087
+            $date_fin = $affdate($f);
1088
+            if ($jour) {
1089
+                $nomjour_debut = nom_jour($d, $abbr);
1090
+                $date_debut = _T('date_fmt_jour', array('nomjour' => $nomjour_debut, 'jour' => $date_debut));
1091
+                $nomjour_fin = nom_jour($f, $abbr);
1092
+                $date_fin = _T('date_fmt_jour', array('nomjour' => $nomjour_fin, 'jour' => $date_fin));
1093
+            }
1094
+            if ($h) {
1095
+                $date_debut = _T('date_fmt_jour_heure', array('jour' => $date_debut, 'heure' => $hd));
1096
+                $date_fin = _T('date_fmt_jour_heure', array('jour' => $date_fin, 'heure' => $hf));
1097
+            }
1098
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1099
+            $date_fin = $dtend . $date_fin . $dtabbr;
1100
+
1101
+            $s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin' => $date_fin));
1102
+        } else {
1103
+            $date_debut = affdate_jourcourt($d, date("Y", $date_fin));
1104
+            $date_fin = $affdate($f);
1105
+            if ($jour) {
1106
+                $nomjour_debut = nom_jour($d, $abbr);
1107
+                $date_debut = _T('date_fmt_jour', array('nomjour' => $nomjour_debut, 'jour' => $date_debut));
1108
+                $nomjour_fin = nom_jour($f, $abbr);
1109
+                $date_fin = _T('date_fmt_jour', array('nomjour' => $nomjour_fin, 'jour' => $date_fin));
1110
+            }
1111
+            if ($h) {
1112
+                $date_debut = _T('date_fmt_jour_heure', array('jour' => $date_debut, 'heure' => $hd));
1113
+                $date_fin = _T('date_fmt_jour_heure', array('jour' => $date_fin, 'heure' => $hf));
1114
+            }
1115
+
1116
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1117
+            $date_fin = $dtend . $date_fin . $dtabbr;
1118
+            $s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin' => $date_fin));
1119
+
1120
+        }
1121
+    }
1122
+
1123
+    return $s;
1124 1124
 }
1125 1125
 
1126 1126
 /**
@@ -1141,10 +1141,10 @@  discard block
 block discarded – undo
1141 1141
  *     Date au format ical
1142 1142
  **/
1143 1143
 function date_ical($date, $addminutes = 0) {
1144
-	list($heures, $minutes, $secondes) = recup_heure($date);
1145
-	list($annee, $mois, $jour) = recup_date($date);
1144
+    list($heures, $minutes, $secondes) = recup_heure($date);
1145
+    list($annee, $mois, $jour) = recup_date($date);
1146 1146
 
1147
-	return gmdate("Ymd\THis\Z", mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1147
+    return gmdate("Ymd\THis\Z", mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1148 1148
 }
1149 1149
 
1150 1150
 
@@ -1168,11 +1168,11 @@  discard block
 block discarded – undo
1168 1168
  *     La date formatée
1169 1169
  **/
1170 1170
 function date_iso($date_heure) {
1171
-	list($annee, $mois, $jour) = recup_date($date_heure);
1172
-	list($heures, $minutes, $secondes) = recup_heure($date_heure);
1173
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1171
+    list($annee, $mois, $jour) = recup_date($date_heure);
1172
+    list($heures, $minutes, $secondes) = recup_heure($date_heure);
1173
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1174 1174
 
1175
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1175
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1176 1176
 }
1177 1177
 
1178 1178
 /**
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
  *     La date formatée
1196 1196
  **/
1197 1197
 function date_822($date_heure) {
1198
-	list($annee, $mois, $jour) = recup_date($date_heure);
1199
-	list($heures, $minutes, $secondes) = recup_heure($date_heure);
1200
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1198
+    list($annee, $mois, $jour) = recup_date($date_heure);
1199
+    list($heures, $minutes, $secondes) = recup_heure($date_heure);
1200
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1201 1201
 
1202
-	return date('r', $time);
1202
+    return date('r', $time);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1215,11 +1215,11 @@  discard block
 block discarded – undo
1215 1215
  *     Date au format `Ymd`
1216 1216
  **/
1217 1217
 function date_anneemoisjour($d) {
1218
-	if (!$d) {
1219
-		$d = date("Y-m-d");
1220
-	}
1218
+    if (!$d) {
1219
+        $d = date("Y-m-d");
1220
+    }
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1222
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
@@ -1235,11 +1235,11 @@  discard block
 block discarded – undo
1235 1235
  *     Date au format `Ym`
1236 1236
  **/
1237 1237
 function date_anneemois($d) {
1238
-	if (!$d) {
1239
-		$d = date("Y-m-d");
1240
-	}
1238
+    if (!$d) {
1239
+        $d = date("Y-m-d");
1240
+    }
1241 1241
 
1242
-	return substr($d, 0, 4) . substr($d, 5, 2);
1242
+    return substr($d, 0, 4) . substr($d, 5, 2);
1243 1243
 }
1244 1244
 
1245 1245
 /**
@@ -1255,13 +1255,13 @@  discard block
 block discarded – undo
1255 1255
  *     Date au lundi de la même semaine au format `Ymd`
1256 1256
  **/
1257 1257
 function date_debut_semaine($annee, $mois, $jour) {
1258
-	$w_day = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
1259
-	if ($w_day == 0) {
1260
-		$w_day = 7;
1261
-	} // Gaffe: le dimanche est zero
1262
-	$debut = $jour - $w_day + 1;
1258
+    $w_day = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
1259
+    if ($w_day == 0) {
1260
+        $w_day = 7;
1261
+    } // Gaffe: le dimanche est zero
1262
+    $debut = $jour - $w_day + 1;
1263 1263
 
1264
-	return date("Ymd", mktime(0, 0, 0, $mois, $debut, $annee));
1264
+    return date("Ymd", mktime(0, 0, 0, $mois, $debut, $annee));
1265 1265
 }
1266 1266
 
1267 1267
 /**
@@ -1277,12 +1277,12 @@  discard block
 block discarded – undo
1277 1277
  *     Date au dimanche de la même semaine au format `Ymd`
1278 1278
  **/
1279 1279
 function date_fin_semaine($annee, $mois, $jour) {
1280
-	$w_day = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
1281
-	if ($w_day == 0) {
1282
-		$w_day = 7;
1283
-	} // Gaffe: le dimanche est zero
1284
-	$debut = $jour - $w_day + 1;
1280
+    $w_day = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
1281
+    if ($w_day == 0) {
1282
+        $w_day = 7;
1283
+    } // Gaffe: le dimanche est zero
1284
+    $debut = $jour - $w_day + 1;
1285 1285
 
1286
-	return date("Ymd", mktime(0, 0, 0, $mois, $debut + 6, $annee));
1286
+    return date("Ymd", mktime(0, 0, 0, $mois, $debut + 6, $annee));
1287 1287
 }
1288 1288
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 function extraire_date($texte) {
39 39
 	// format = 2001-08
40 40
 	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),", $texte, $regs)) {
41
-		return $regs[1] . "-" . sprintf("%02d", $regs[2]) . "-01";
41
+		return $regs[1]."-".sprintf("%02d", $regs[2])."-01";
42 42
 	}
43 43
 }
44 44
 
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 		if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
70 70
 			$regs = array_pad($regs, 4, null); // eviter notice php
71
-			$date = $regs[1] . "-00-00" . $regs[3];
71
+			$date = $regs[1]."-00-00".$regs[3];
72 72
 		} else {
73 73
 			if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
74 74
 				$regs = array_pad($regs, 4, null); // eviter notice php
75
-				$date = preg_replace("@/@", "-", $regs[1]) . "-00" . $regs[3];
75
+				$date = preg_replace("@/@", "-", $regs[1])."-00".$regs[3];
76 76
 			} else {
77 77
 				$date = date("Y-m-d H:i:s", strtotime($date));
78 78
 			}
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
  *	- si 'abbr' ne précise pas l'unité des minutes : 12h10
203 203
  * @return string L'heure formatée dans la langue en cours.
204 204
  **/
205
-function heures_minutes($numdate, $forme='') {
206
-	if ($forme !='abbr') {
205
+function heures_minutes($numdate, $forme = '') {
206
+	if ($forme != 'abbr') {
207 207
 		return _T('date_fmt_heures_minutes', array('h' => heures($numdate), 'm' => minutes($numdate)));
208 208
 	}
209 209
 	else {
@@ -375,17 +375,17 @@  discard block
 block discarded – undo
375 375
 	if ($decal > 3600 * 24 * 30) {
376 376
 		$mois = floor($decal / (3600 * 24 * 30));
377 377
 		if ($mois < 2) {
378
-			$delai = "$mois " . _T("date_un_mois");
378
+			$delai = "$mois "._T("date_un_mois");
379 379
 		} else {
380
-			$delai = "$mois " . _T("date_mois");
380
+			$delai = "$mois "._T("date_mois");
381 381
 		}
382 382
 	} else {
383 383
 		if ($decal > 3600 * 24 * 7) {
384 384
 			$semaines = floor($decal / (3600 * 24 * 7));
385 385
 			if ($semaines < 2) {
386
-				$delai = "$semaines " . _T("date_une_semaine");
386
+				$delai = "$semaines "._T("date_une_semaine");
387 387
 			} else {
388
-				$delai = "$semaines " . _T("date_semaines");
388
+				$delai = "$semaines "._T("date_semaines");
389 389
 			}
390 390
 		} else {
391 391
 			if ($decal > 3600 * 24) {
@@ -393,30 +393,30 @@  discard block
 block discarded – undo
393 393
 				if ($jours < 2) {
394 394
 					return $il_y_a == "date_dans" ? _T("date_demain") : _T("date_hier");
395 395
 				} else {
396
-					$delai = "$jours " . _T("date_jours");
396
+					$delai = "$jours "._T("date_jours");
397 397
 				}
398 398
 			} else {
399 399
 				if ($decal >= 3600) {
400 400
 					$heures = floor($decal / 3600);
401 401
 					if ($heures < 2) {
402
-						$delai = "$heures " . _T("date_une_heure");
402
+						$delai = "$heures "._T("date_une_heure");
403 403
 					} else {
404
-						$delai = "$heures " . _T("date_heures");
404
+						$delai = "$heures "._T("date_heures");
405 405
 					}
406 406
 				} else {
407 407
 					if ($decal >= 60) {
408 408
 						$minutes = floor($decal / 60);
409 409
 						if ($minutes < 2) {
410
-							$delai = "$minutes " . _T("date_une_minute");
410
+							$delai = "$minutes "._T("date_une_minute");
411 411
 						} else {
412
-							$delai = "$minutes " . _T("date_minutes");
412
+							$delai = "$minutes "._T("date_minutes");
413 413
 						}
414 414
 					} else {
415 415
 						$secondes = ceil($decal);
416 416
 						if ($secondes < 2) {
417
-							$delai = "$secondes " . _T("date_une_seconde");
417
+							$delai = "$secondes "._T("date_une_seconde");
418 418
 						} else {
419
-							$delai = "$secondes " . _T("date_secondes");
419
+							$delai = "$secondes "._T("date_secondes");
420 420
 						}
421 421
 					}
422 422
 				}
@@ -511,16 +511,16 @@  discard block
 block discarded – undo
511 511
 		$njour = 0;
512 512
 	} else {
513 513
 		$njour = intval($jour);
514
-		if ($jourth = _T('date_jnum' . $jour)) {
514
+		if ($jourth = _T('date_jnum'.$jour)) {
515 515
 			$jour = $jourth;
516 516
 		}
517 517
 	}
518 518
 
519 519
 	$mois = intval($mois);
520 520
 	if ($mois > 0 and $mois < 13) {
521
-		$nommois = _T('date_mois_' . $mois);
521
+		$nommois = _T('date_mois_'.$mois);
522 522
 		if ($jour) {
523
-			$jourmois = _T('date_de_mois_' . $mois, array('j' => $jour, 'nommois' => $nommois));
523
+			$jourmois = _T('date_de_mois_'.$mois, array('j' => $jour, 'nommois' => $nommois));
524 524
 		} else {
525 525
 			$jourmois = $nommois;
526 526
 		}
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 	}
531 531
 
532 532
 	if ($annee < 0) {
533
-		$annee = -$annee . " " . _T('date_avant_jc');
533
+		$annee = -$annee." "._T('date_avant_jc');
534 534
 		$avjc = true;
535 535
 	} else {
536 536
 		$avjc = false;
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
 				}
557 557
 			}
558 558
 			if ($vue == 'saison') {
559
-				return $saison ? _T('date_saison_' . $saison) : '';
559
+				return $saison ? _T('date_saison_'.$saison) : '';
560 560
 			} else {
561 561
 				return $saison ? trim(_T('date_fmt_saison_annee',
562
-					array('saison' => _T('date_saison_' . $saison), 'annee' => $annee))) : '';
562
+					array('saison' => _T('date_saison_'.$saison), 'annee' => $annee))) : '';
563 563
 			}
564 564
 
565 565
 		case 'court':
@@ -608,9 +608,9 @@  discard block
 block discarded – undo
608 608
 			}
609 609
 
610 610
 		case 'nom_mois':
611
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
611
+			$param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : '');
612 612
 			if ($param and $mois) {
613
-				return _T('date_mois_' . $mois . $param);
613
+				return _T('date_mois_'.$mois.$param);
614 614
 			}
615 615
 
616 616
 			return $nommois;
@@ -630,9 +630,9 @@  discard block
 block discarded – undo
630 630
 			}
631 631
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
632 632
 			$nom = 1 + date('w', $nom);
633
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
633
+			$param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : '');
634 634
 
635
-			return _T('date_jour_' . $nom . $param);
635
+			return _T('date_jour_'.$nom.$param);
636 636
 
637 637
 		case 'mois_annee':
638 638
 			if ($avjc) {
@@ -1027,8 +1027,8 @@  discard block
 block discarded – undo
1027 1027
 
1028 1028
 	$dtstart = $dtend = $dtabbr = "";
1029 1029
 	if (strpos($forme, 'hcal') !== false) {
1030
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1031
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1030
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1031
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1032 1032
 		$dtabbr = "</abbr>";
1033 1033
 	}
1034 1034
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
 			}
1073 1073
 		} else {
1074 1074
 			if ($dtabbr && $dtstart) {
1075
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1075
+				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1076 1076
 			} else {
1077 1077
 				$s = spip_ucfirst($s);
1078 1078
 			}
@@ -1095,8 +1095,8 @@  discard block
 block discarded – undo
1095 1095
 				$date_debut = _T('date_fmt_jour_heure', array('jour' => $date_debut, 'heure' => $hd));
1096 1096
 				$date_fin = _T('date_fmt_jour_heure', array('jour' => $date_fin, 'heure' => $hf));
1097 1097
 			}
1098
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1099
-			$date_fin = $dtend . $date_fin . $dtabbr;
1098
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1099
+			$date_fin = $dtend.$date_fin.$dtabbr;
1100 1100
 
1101 1101
 			$s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin' => $date_fin));
1102 1102
 		} else {
@@ -1113,8 +1113,8 @@  discard block
 block discarded – undo
1113 1113
 				$date_fin = _T('date_fmt_jour_heure', array('jour' => $date_fin, 'heure' => $hf));
1114 1114
 			}
1115 1115
 
1116
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1117
-			$date_fin = $dtend . $date_fin . $dtabbr;
1116
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1117
+			$date_fin = $dtend.$date_fin.$dtabbr;
1118 1118
 			$s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin' => $date_fin));
1119 1119
 
1120 1120
 		}
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		$d = date("Y-m-d");
1220 1220
 	}
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1222
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
 		$d = date("Y-m-d");
1240 1240
 	}
1241 1241
 
1242
-	return substr($d, 0, 4) . substr($d, 5, 2);
1242
+	return substr($d, 0, 4).substr($d, 5, 2);
1243 1243
 }
1244 1244
 
1245 1245
 /**
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -205,8 +205,7 @@
 block discarded – undo
205 205
 function heures_minutes($numdate, $forme='') {
206 206
 	if ($forme !='abbr') {
207 207
 		return _T('date_fmt_heures_minutes', array('h' => heures($numdate), 'm' => minutes($numdate)));
208
-	}
209
-	else {
208
+	} else {
210 209
 		return _T('date_fmt_heures_minutes_court', array('h' => heures($numdate), 'm' => minutes($numdate)));
211 210
 	}
212 211
 }
Please login to merge, or discard this patch.