fix: use IntlDateFormatter instead of strftime
This CL introduces breaking changes, since it uses non-constant static
variable initializers, which are only available since PHP 8.3. Thus, the
codebase now only supports PHP 8.3 (and the docs have been modified to
reflect this and the fact that the Intl extension is necessary).
Fixed: hores:2
GitOrigin-RevId: 9a91312c96b90fa4c9ae5fc5f6e972fd95c9cd57
diff --git a/src/inc/date.php b/src/inc/date.php
new file mode 100644
index 0000000..ba89c09
--- /dev/null
+++ b/src/inc/date.php
@@ -0,0 +1,35 @@
+<?php
+class date {
+ const LOCALE = 'es';
+
+ private static function createFormatter(string $pattern) {
+ return new IntlDateFormatter(
+ locale: self::LOCALE,
+ dateType: IntlDateFormatter::FULL,
+ timeType: IntlDateFormatter::FULL,
+ timezone: null,
+ calendar: IntlDateFormatter::GREGORIAN,
+ pattern: $pattern
+ );
+ }
+
+ public static function getMonthYear(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
+ static $formatter = self::createFormatter("MMMM yyyy");
+ return $formatter->format($timestamp);
+ }
+
+ public static function getShortDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
+ static $formatter = self::createFormatter("dd MMM yyyy");
+ return $formatter->format($timestamp);
+ }
+
+ public static function getShortDateWithTime(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
+ static $formatter = self::createFormatter("dd MMM yyyy HH:mm:ss");
+ return $formatter->format($timestamp);
+ }
+
+ public static function getLongDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
+ static $formatter = self::createFormatter("dd 'de' MMMM 'de' yyyy");
+ return $formatter->format($timestamp);
+ }
+}