Skip to content

Conversation

@amitsharmadoj
Copy link

Fix issue 200 (#200), an issue with the creation of date only fields

$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.

@jhedstrom
Copy link
Owner

The reason the old code uses that format is that even for date-only fields, the actual storage has the entire date and time string.

@amitsharmadoj
Copy link
Author

Yes this is what my understanding is. Ideally date-only fields should have been created with and without the timestamp but not happening with timestamp for me. Perhaps there is a change in Drupal core 8.6.x the way it handles the Date.

@MPParsley
Copy link
Contributor

MPParsley commented Jul 15, 2020

Running into the same issue, I have a date only field but I can set the value:

    When I am viewing a "page" content:
      | langcode   | nl         |
      | title      | Title.     |
      | field_date | 2020-07-14 |

field_date remains empty.

This patch fixed the issue.

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.

3 participants