✨ (date): add a tool to pretty print archive dates
This commit is contained in:
parent
21787c8203
commit
34fd8b57ff
2 changed files with 34 additions and 0 deletions
|
@ -2,6 +2,21 @@
|
||||||
|
|
||||||
class Date {
|
class Date {
|
||||||
|
|
||||||
|
private const MONTHS = [
|
||||||
|
"01" => "January",
|
||||||
|
"02" => "February",
|
||||||
|
"03" => "March",
|
||||||
|
"04" => "April",
|
||||||
|
"05" => "May",
|
||||||
|
"06" => "June",
|
||||||
|
"07" => "July",
|
||||||
|
"08" => "August",
|
||||||
|
"09" => "September",
|
||||||
|
"10" => "October",
|
||||||
|
"11" => "November",
|
||||||
|
"12" => "December"
|
||||||
|
];
|
||||||
|
|
||||||
// Returns string with the date translated
|
// Returns string with the date translated
|
||||||
// Example: $date = 'Mon, 27th March' > 'Lun, 27th Marzo'
|
// Example: $date = 'Mon, 27th March' > 'Lun, 27th Marzo'
|
||||||
public static function translate($date)
|
public static function translate($date)
|
||||||
|
@ -127,4 +142,22 @@ class Date {
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function getMonthName($month) {
|
||||||
|
return isset(self::MONTHS[$month]) ? self::MONTHS[$month] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function prettyArchiveDate($date) {
|
||||||
|
global $L;
|
||||||
|
$explodedDate = explode("-", $date);
|
||||||
|
try {
|
||||||
|
if (sizeof($explodedDate) > 2) {
|
||||||
|
return $date;
|
||||||
|
} else {
|
||||||
|
return self::translate(self::getMonthName($explodedDate[1])." ".$explodedDate[0]);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $L->g("Invalid Date");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,6 +166,7 @@
|
||||||
"current-format": "Format actuel",
|
"current-format": "Format actuel",
|
||||||
"version": "Version",
|
"version": "Version",
|
||||||
"author": "Auteur",
|
"author": "Auteur",
|
||||||
|
"authors": "Auteurs",
|
||||||
"activate": "Activer",
|
"activate": "Activer",
|
||||||
"deactivate": "Désactiver",
|
"deactivate": "Désactiver",
|
||||||
"edit-category": "Modifier la catégorie",
|
"edit-category": "Modifier la catégorie",
|
||||||
|
|
Loading…
Reference in a new issue