blob: ba89c093a396fdfe04a9ce6eda0e8bd9da3e1028 [file] [log] [blame]
Adrià Vilanova Martínezeaee4a92023-12-03 21:07:21 +01001<?php
2class date {
3 const LOCALE = 'es';
4
5 private static function createFormatter(string $pattern) {
6 return new IntlDateFormatter(
7 locale: self::LOCALE,
8 dateType: IntlDateFormatter::FULL,
9 timeType: IntlDateFormatter::FULL,
10 timezone: null,
11 calendar: IntlDateFormatter::GREGORIAN,
12 pattern: $pattern
13 );
14 }
15
16 public static function getMonthYear(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
17 static $formatter = self::createFormatter("MMMM yyyy");
18 return $formatter->format($timestamp);
19 }
20
21 public static function getShortDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
22 static $formatter = self::createFormatter("dd MMM yyyy");
23 return $formatter->format($timestamp);
24 }
25
26 public static function getShortDateWithTime(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
27 static $formatter = self::createFormatter("dd MMM yyyy HH:mm:ss");
28 return $formatter->format($timestamp);
29 }
30
31 public static function getLongDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
32 static $formatter = self::createFormatter("dd 'de' MMMM 'de' yyyy");
33 return $formatter->format($timestamp);
34 }
35}