dgrigg / craft-migration-assistant

Migration Manager for Craft CMS
Other
27 stars 10 forks source link

Entry import is disregarding post/expiry date timezones #10

Closed brandonkelly closed 5 years ago

brandonkelly commented 5 years ago

These lines:

https://github.com/dgrigg/craft-migration-assistant/blob/4a9ceff667cb183b96322824df003b0374b9e81d/src/services/EntriesContent.php#L145-L146

Should be accounting for the timezone stored in the array:

{"date":"2019-07-21 17:14:00.000000","timezone_type":3,"timezone":"Europe/Brussels"}

For example you could do this:

$entry->postDate = is_null($data['postDate']) ? '' : new DateTime($data['postDate']['date'], new DateTimeZone($data['postDate']['timezone']));
$entry->expiryDate = is_null($data['expiryDate']) ? '' : new DateTime($data['expiryDate']['date'], new DateTimeZone($data['expiryDate']['timezone']));

I’ve also just updated DateTimeHelper::toDateTime() to support passing in PHP DateTime arrays like the above (craftcms/cms@ad2f39e84654550db8b69a7d39cbf88928cdd4af), so alternatively your next release could require "craftcms/cms": "^3.2.6" and do this instead:

$entry->postDate = is_null($data['postDate']) ? '' : DateTimeHelper::toDateTime($data['postDate']);
$entry->expiryDate = is_null($data['expiryDate']) ? '' : DateTimeHelper::toDateTime($data['expiryDate']);

(Leave out the ['date'] subs.)

dgrigg commented 5 years ago

thanks @brandonkelly, issue has been resolved.