[Agrega] a utilis una función para formatear el número de un mes

This commit is contained in:
Ricardo García Jiménez 2022-02-21 11:56:14 -06:00
parent 086809524c
commit 2b50a53b12
3 changed files with 51 additions and 42 deletions

View file

@ -169,48 +169,9 @@ class articlesController {
// Segmenta la fecha en un array asociativo.
$date = date_parse($article['date']);
switch ($date['month']) {
case 1:
$month = 'Enero';
break;
case 2:
$month = 'Febrero';
break;
case 3:
$month = 'Marzo';
break;
case 4:
$month = 'Abril';
break;
case 5:
$month = 'Mayo';
break;
case 6:
$month = 'Junio';
break;
case 7:
$month = 'Julio';
break;
case 8:
$month = 'Agosto';
break;
case 9:
$month = 'Septiembre';
break;
case 10:
$month = 'Octubre';
break;
case 11:
$month = 'Noviembre';
break;
case 12:
$month = 'Diciembre';
break;
default:
$month = '';
}
$date = utils::format_month($date);
$article['date'] = $date['day'] . ' de ' . $month . ' del ' . $date['year'];
$article['date'] = $date['day'] . ' de ' . $date['month'] . ' del ' . $date['year'];
unset($validations, $data, $articlesModel, $parsedown, $date, $month);

View file

@ -164,4 +164,52 @@ class utils {
return $search;
}
// Formatea el número de un mes en palabras.
public static function format_month(array $date) {
switch ($date['month']) {
case 1:
$month = 'Enero';
break;
case 2:
$month = 'Febrero';
break;
case 3:
$month = 'Marzo';
break;
case 4:
$month = 'Abril';
break;
case 5:
$month = 'Mayo';
break;
case 6:
$month = 'Junio';
break;
case 7:
$month = 'Julio';
break;
case 8:
$month = 'Agosto';
break;
case 9:
$month = 'Septiembre';
break;
case 10:
$month = 'Octubre';
break;
case 11:
$month = 'Noviembre';
break;
case 12:
$month = 'Diciembre';
break;
default:
$month = '';
}
$date['month'] = $month;
return $date;
}
}

View file

@ -60,7 +60,7 @@
<div class="post__info">
<p class="post__author-name">
<a href="<?= $article['profile'] ?>">
<?= $article['author'] ?>
<?= $article['username'] ?>
</a>
</p>
<p class="post__date">