protected function fixTimeZoneOnDenormalization($object, $denormalized, \DateTimeZone $orgTimezone): void
    {
        // Change timezone of all date objects to organization's current
        // timezone if it is different than the default PHP timezone.

        if (date_default_timezone_get() !== $orgTimezone->getName()) {
            $ro = new \ReflectionObject($denormalized);
            // @psalm-suppress required since symfony/serializer >= 4.2.0
            // @see https://github.com/symfony/symfony/pull/28709
            /** @psalm-suppress InvalidArgument */
            $dateDenormalizer = new DateTimeNormalizer(EntityInterface::DATE_FORMAT, $orgTimezone);
            foreach ($object as $prop_name => $prop_value) {
                if ($ro->hasProperty($prop_name)) {
                    $property = $ro->getProperty($prop_name);
                    $property->setAccessible(true);
                    $value = $property->getValue($denormalized);
                    if ($value instanceof \DateTimeImmutable) {
                        $property->setValue($denormalized, $dateDenormalizer->denormalize($prop_value, \DateTimeImmutable::class));
                    }
                }
            }
        }
    }
protected function fixTimeZoneOnDenormalization($object, $denormalized, \DateTimeZone $orgTimezone): void
    {
        // Change timezone of all date objects to organization's current
        // timezone if it is different than the default PHP timezone.

        if (date_default_timezone_get() !== $orgTimezone->getName()) {
            $ro = new \ReflectionObject($denormalized);
            // @psalm-suppress required since symfony/serializer >= 4.2.0
            // @see https://github.com/symfony/symfony/pull/28709
            /** @psalm-suppress InvalidArgument */
            $dateDenormalizer = new DateTimeNormalizer(EntityInterface::DATE_FORMAT, $orgTimezone);
            foreach ($object as $prop_name => $prop_value) {
                if ($ro->hasProperty($prop_name)) {
                    $property = $ro->getProperty($prop_name);
                    $property->setAccessible(true);
                    $value = $property->getValue($denormalized);
                    if ($value instanceof \DateTimeImmutable) {
                        $property->setValue($denormalized, $dateDenormalizer->denormalize($prop_value, \DateTimeImmutable::class));
                    }
                }
            }
        }
    }
protected function fixTimeZoneOnDenormalization ( $ object , $ denormalized , \ DateTimeZone $ orgTimezone ) : void { // Change timezone of all date objects to organization's current // timezone if it is different than the default PHP timezone. if ( date_default_timezone_get ( ) !== $ orgTimezone -> getName ( ) ) { $ ro = new \ ReflectionObject ( $ denormalized ) ; // @psalm-suppress required since symfony/serializer >= 4.2.0 // @see https://github.com/symfony/symfony/pull/28709 /** @psalm-suppress InvalidArgument */ $ dateDenormalizer = new DateTimeNormalizer ( EntityInterface :: DATE_FORMAT , $ orgTimezone ) ; foreach ( $ object as $ prop_name => $ prop_value ) { if ( $ ro -> hasProperty ( $ prop_name ) ) { $ property = $ ro -> getProperty ( $ prop_name ) ; $ property -> setAccessible ( true ) ; $ value = $ property -> getValue ( $ denormalized ) ; if ( $ value instanceof \ DateTimeImmutable ) { $ property -> setValue ( $ denormalized , $ dateDenormalizer -> denormalize ( $ prop_value , \ DateTimeImmutable :: class ) ) ; } } } } }
Corrects the timezone on all DateTimeImmutable objects if the
organization's current timezone is not the default UTC.

It process object properties non-recursively because it gets called
on nested object automatically.

@param object $object
The object that got denormalized.
@param object $denormalized
The denormalized object.
@param \DateTimeZone $orgTimezone
Timezone of the organization retrieved from the organization profile.
Corrects the timezone on all DateTimeImmutable objects if the organization s current timezone is not the default UTC .