-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
7 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters