Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 200 fix issue with creation of date only fields #201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Drupal/Driver/Fields/Drupal8/DatetimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ public function expand($values) {
// uses UTC for internal storage. If no timezone is specified in a date
// 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);
$values[$key] = $date->format('Y-m-d\TH:i:s');
if (DateTime::createFromFormat('Y-m-d', $value) !== FALSE) {
Copy link
Owner

Choose a reason for hiding this comment

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

Would this ever return FALSE?

Copy link
Author

Choose a reason for hiding this comment

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

Yes it returns FALSE when value is of datetime type e.g. 2017-04-02T05:00:00.

// Handle 'Date only' date type.
$date = new DateTime($value);
$formattedDate = $date->format('Y-m-d');
}
else {
$date = new DateTime($value, $siteTimezone);
$date->setTimezone($storageTimezone);
$formattedDate = $date->format('Y-m-d\TH:i:s');
}
$values[$key] = $formattedDate;
}
}
return $values;
Expand Down