Skip to content

fix: consider time zone during migration of orders#184

Draft
Dennis Garding (DennisGarding) wants to merge 2 commits intotrunkfrom
14186/time-zone-diff
Draft

fix: consider time zone during migration of orders#184
Dennis Garding (DennisGarding) wants to merge 2 commits intotrunkfrom
14186/time-zone-diff

Conversation

@DennisGarding
Copy link
Copy Markdown
Contributor

closes: #14184

Gets time zone from source db and consider it during migration of orders

* @param array<string, mixed> $converted
* @param array<string, mixed> $data
*/
private function convertOrderDateTime(array &$converted, array &$data): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there more datatime fields that would need something like that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I also think there are likely more cases we have to adjust. Just searching through the migration-assistant codebase for datetime in PHP files already reveals some more...

Looks like basically any time we call

$this->convertValue(..., self::TYPE_DATETIME);
// or
$this->convertValue(..., 'datetime');

it should consider the source system timezone instead of assume its UTC as SW6. Means we need a more general proper fix for this instead of just fixing this one place for order times.

$orderEsd = $this->getOrderEsd($migrationContext);
$orderDetails = $this->getOrderDetails($migrationContext);
$orderDocuments = $this->getOrderDocuments($migrationContext);
$timezone = $this->getDatabaseTimezone($migrationContext);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not still possible to have a mismatch here? Is the database timezone always aligned with the source shop's timezone?

$orderDateTime = new \DateTimeImmutable($data['ordertime'], new \DateTimeZone($sourceTimezone));
$converted['orderDateTime'] = $orderDateTime
->setTimezone(new \DateTimeZone(self::UTC_TIMEZONE))
->format(\DATE_ATOM);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Defaults::STORAGE_DATE_TIME_FORMAT instead, because thats what SW6 uses right?

* @param array<string, mixed> $converted
* @param array<string, mixed> $data
*/
private function convertOrderDateTime(array &$converted, array &$data): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I also think there are likely more cases we have to adjust. Just searching through the migration-assistant codebase for datetime in PHP files already reveals some more...

Looks like basically any time we call

$this->convertValue(..., self::TYPE_DATETIME);
// or
$this->convertValue(..., 'datetime');

it should consider the source system timezone instead of assume its UTC as SW6. Means we need a more general proper fix for this instead of just fixing this one place for order times.

Comment on lines +163 to +172
<<<'SQL'
SELECT timeZones.timeZone
FROM (
SELECT @@SESSION.time_zone AS timeZone
UNION
SELECT @@system_time_zone AS timeZone
) AS timeZones
WHERE timeZone != 'SYSTEM'
LIMIT 1
SQL
Copy link
Copy Markdown
Contributor

@MalteJanz Malte Janz (MalteJanz) Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the most reliable way to figure out the storage timezone for SW5?
Because in my local dev system running this query on either my SW6 or SW5 database, both return CEST, while SW6 for example clearly stores all datetimes in UTC, means the DB timezone might not matter at all for the application?
Is there maybe some configuration value in SW5 to change it? Or does SW5 store its values with the timezone? I think in SW6 its programmatically hard coded in multiple places like:

https://github.com/shopware/shopware/blob/31828222cf8ef317198f9c3a0e568d3443479102/src/Core/Framework/DataAbstractionLayer/FieldSerializer/DateTimeFieldSerializer.php#L52-L54

Comment on lines +161 to +162
if ($timezone !== null) {
$order['_timezone'] = $timezone;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, why would you add this timezone data to each order while it is the same for every order, or even every entity that comes from SW5.

You should read that once from the source system and store it e.g. in a mapping for easy lookup 🤔

@larskemper Lars Kemper (larskemper) marked this pull request as draft April 28, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timezone differences between source and target systems

4 participants