From e778cb87268ab17bb89c6cc5f4479ab2974b41b4 Mon Sep 17 00:00:00 2001 From: jonathanjfshaw Date: Tue, 19 Dec 2017 15:03:45 +0000 Subject: [PATCH 1/2] Reroll & simplify 2 --- .../Driver/Fields/Drupal8/DatetimeHandler.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php b/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php index 006db8fc..9325c06a 100644 --- a/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php +++ b/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php @@ -2,6 +2,9 @@ namespace Drupal\Driver\Fields\Drupal8; +use DateTime; +use DateTimeZone; + /** * Datetime field handler for Drupal 8. */ @@ -11,6 +14,8 @@ class DatetimeHandler extends AbstractHandler { * {@inheritdoc} */ public function expand($values) { + $siteTimezone = new DateTimeZone(\Drupal::config('system.date')->get('timezone.default')); + $storageTimezone = new DateTimeZone(DATETIME_STORAGE_TIMEZONE); foreach ($values as $key => $value) { if (strpos($value, "relative:") !== FALSE) { $relative = trim(str_replace('relative:', '', $value)); @@ -18,7 +23,13 @@ public function expand($values) { $values[$key] = substr(gmdate('c', strtotime($relative)), 0, 19); } else { - $values[$key] = str_replace(' ', 'T', $value); + // A Drupal install has a default site timezone, but nonetheless + // uses UTC for internal storage. If no timezone is specified in a date + // field value by the step author, assume it is in the default timezone of + // the Drupal install, and therefore transform it into UTC for storage. + $date = new DateTime($value, $siteTimezone); + $date->setTimezone($storageTimezone); + $values[$key] = $date->format('Y-m-d\TH:i:s'); } } return $values; From b84dfea096dcb3a262e857a22fd718a82eb23536 Mon Sep 17 00:00:00 2001 From: jonathanjfshaw Date: Tue, 19 Dec 2017 15:17:09 +0000 Subject: [PATCH 2/2] CS: Comment line length --- src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php b/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php index 9325c06a..2b17f1c9 100644 --- a/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php +++ b/src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php @@ -25,7 +25,7 @@ public function expand($values) { else { // A Drupal install has a default site timezone, but nonetheless // uses UTC for internal storage. If no timezone is specified in a date - // field value by the step author, assume it is in the default timezone of + // field value by the step author, assume the default timezone of // the Drupal install, and therefore transform it into UTC for storage. $date = new DateTime($value, $siteTimezone); $date->setTimezone($storageTimezone);