You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).
If you specify the timezone when denormalizing, you'd expect all datetimes to come out in that timezone, regardless of (user) input. This currently does not happen.
How to reproduce
$normalizer = new \Symfony\Component\Serializer\Normalizer\DateTimeNormalizer(
[
\Symfony\Component\Serializer\Normalizer\DateTimeNormalizer::TIMEZONE_KEY => 'UTC'
]
);
$datetime = $normalizer->denormalize('2016-01-27T16:39:26+01:00', \DateTimeInterface::class);
// should be in UTC, but it's exactly the same as input, +01:00var_dump($datetime->format(\DATE_RFC3339));
Possible Solution
When denormalizing, specify the timezone after having created the \DateTime instance, not in the constructor.
Additional context
using in API Platform context means the datetime string is passed directly to this denormalizer, allowing the user to control the timezone of the created \DateTime instances