Adrià Vilanova MartÃnez | eaee4a9 | 2023-12-03 21:07:21 +0100 | [diff] [blame] | 1 | <?php |
| 2 | class 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 | } |