W3cubDocs

/Symfony 4.1

DateTimeToHtml5LocalDateTimeTransformer

class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer

Constants

HTML5_FORMAT

Properties

static protected $formats from BaseDateTimeTransformer
protected $inputTimezone from BaseDateTimeTransformer
protected $outputTimezone from BaseDateTimeTransformer

Methods

__construct(string $inputTimezone = null, string $outputTimezone = null) from BaseDateTimeTransformer
mixed transform(DateTime|DateTimeInterface $dateTime)

Transforms a \DateTime into a local date and time string.

mixed reverseTransform(string $dateTimeLocal)

Transforms a local date and time string into a \DateTime.

Details

__construct(string $inputTimezone = null, string $outputTimezone = null)

Parameters

string $inputTimezone The name of the input timezone
string $outputTimezone The name of the output timezone

Exceptions

InvalidArgumentException if a timezone is not valid

mixed transform(DateTime|DateTimeInterface $dateTime)

Transforms a \DateTime into a local date and time string.

According to the HTML standard, the input string of a datetime-local input is a RFC3339 date followed by 'T', followed by a RFC3339 time. https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string

Parameters

DateTime|DateTimeInterface $dateTime A DateTime object

Return Value

mixed The value in the transformed representation

Exceptions

TransformationFailedException If the given value is not an instance of \DateTime or \DateTimeInterface

mixed reverseTransform(string $dateTimeLocal)

Transforms a local date and time string into a \DateTime.

When transforming back to DateTime the regex is slightly laxer, taking into account rules for parsing a local date and time string https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#parse-a-local-date-and-time-string

Parameters

string $dateTimeLocal Formatted string

Return Value

mixed The value in the original representation

Exceptions

TransformationFailedException If the given value is not a string, if the value could not be transformed