(date): add a tool to pretty print archive dates

This commit is contained in:
Kazhnuz 2025-01-19 16:46:45 +01:00
parent 21787c8203
commit 34fd8b57ff
2 changed files with 34 additions and 0 deletions

View file

@ -2,6 +2,21 @@
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
// Example: $date = 'Mon, 27th March' > 'Lun, 27th Marzo'
public static function translate($date)
@ -127,4 +142,22 @@ class Date {
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");
}
}
}

View file

@ -166,6 +166,7 @@
"current-format": "Format actuel",
"version": "Version",
"author": "Auteur",
"authors": "Auteurs",
"activate": "Activer",
"deactivate": "Désactiver",
"edit-category": "Modifier la catégorie",