Skip to content

DateTimeFacade

Lightweight modern replacement for legacy DateFormat / calendar stack.

Responsibilities: - Parse simple datetime strings with a subset of legacy pattern tokens (yyyy, MM, dd, HH, mm, ss) - Format DateTimeInterface using same subset - Provide explicit timezone & locale handling without custom Olson DB. This is intentionally minimal; extend only when concrete application usages require more tokens.

Formatting and parsing both go through IntlDateFormatter: ext-intl is a hard requirement of the framework (see composer.json), so there is no second implementation to keep in step — one that would, being locale-blind, quietly disagree with this one.

The supported tokens are spelled the same way in ICU, so a pattern is handed to ICU as written; DateTimeFacade::assertSupportedTokens() is what keeps a pattern inside that subset.

final class DateTimeFacade

SourceI18n/DateTimeFacade.php
MethodDescription
format(DateTimeInterface $dt, string $pattern, ?string $locale = null): stringFormat a DateTime using a legacy-style pattern.
parse(string $value, string $pattern, ?string $timezone = null, ?string $locale = null): DateTimeImmutableParse a datetime string according to a legacy-style pattern.

public static function format(DateTimeInterface $dt, string $pattern, ?string $locale = null): string

Format a DateTime using a legacy-style pattern.

ParameterTypeDescription
$dtDateTimeInterface
$patternstring
$locale?``string

Returns string

ThrowsWhen
RuntimeExceptionif the pattern holds an unsupported token, or ICU cannot format the value.

public static function parse(string $value, string $pattern, ?string $timezone = null, ?string $locale = null): DateTimeImmutable

Parse a datetime string according to a legacy-style pattern.

Supports fixed-width tokens: yyyy, MM, dd, HH, mm, ss (24h clock).

The whole value must be consumed, so trailing text is a parse failure rather than something silently ignored.

ParameterTypeDescription
$valuestring
$patternstring
$timezone?``string
$locale?``string

Returns DateTimeImmutable

ThrowsWhen
RuntimeExceptionif the pattern holds an unsupported token, or the value does not parse against it.