function DateTimeNormalizerContextBuilder::withTimezone
Configures the timezone of the date.
It could be either a \DateTimeZone or a string that will be used to construct the \DateTimeZone
Throws
See also
https://secure.php.net/manual/en/class.datetimezone.php
File
-
vendor/
symfony/ serializer/ Context/ Normalizer/ DateTimeNormalizerContextBuilder.php, line 48
Class
- DateTimeNormalizerContextBuilder
- A helper providing autocompletion for available DateTimeNormalizer options.
Namespace
Symfony\Component\Serializer\Context\NormalizerCode
public function withTimezone(\DateTimeZone|string|null $timezone) : static {
if (null === $timezone) {
return $this->with(DateTimeNormalizer::TIMEZONE_KEY, null);
}
if (\is_string($timezone)) {
try {
$timezone = new \DateTimeZone($timezone);
} catch (\Exception $e) {
throw new InvalidArgumentException(\sprintf('The "%s" timezone is invalid.', $timezone), previous: $e);
}
}
return $this->with(DateTimeNormalizer::TIMEZONE_KEY, $timezone);
}