blob: 742a4be1611626f3f31e70d6594a77ac73211869 [file] [log] [blame]
Adrià Vilanova Martínezeaee4a92023-12-03 21:07:21 +01001<?php
Adrià Vilanova Martínez4b140462023-12-03 21:18:43 +01002/*
3 * hores
4 * Copyright (c) 2023 Adrià Vilanova Martínez
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program.
18 * If not, see http://www.gnu.org/licenses/.
19 */
20
Adrià Vilanova Martínezeaee4a92023-12-03 21:07:21 +010021class date {
22 const LOCALE = 'es';
23
24 private static function createFormatter(string $pattern) {
25 return new IntlDateFormatter(
26 locale: self::LOCALE,
27 dateType: IntlDateFormatter::FULL,
28 timeType: IntlDateFormatter::FULL,
29 timezone: null,
30 calendar: IntlDateFormatter::GREGORIAN,
31 pattern: $pattern
32 );
33 }
34
35 public static function getMonthYear(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
36 static $formatter = self::createFormatter("MMMM yyyy");
37 return $formatter->format($timestamp);
38 }
39
40 public static function getShortDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
41 static $formatter = self::createFormatter("dd MMM yyyy");
42 return $formatter->format($timestamp);
43 }
44
45 public static function getShortDateWithTime(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
46 static $formatter = self::createFormatter("dd MMM yyyy HH:mm:ss");
47 return $formatter->format($timestamp);
48 }
49
50 public static function getLongDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
51 static $formatter = self::createFormatter("dd 'de' MMMM 'de' yyyy");
52 return $formatter->format($timestamp);
53 }
54}