Problem/Motivation
The DateTimeIso8601::getDateTime()
method on the @DataType=datetime_iso8601
plugin incorrectly constructs a \Drupal\Core\Datetime\DrupalDateTime
object: it forgot to specify the timezone of the stored value (which is always UTC).
In Drupal core, there are zero calls to DateTimeIso8601::getDateTime()
. Only tests are calling it. It's thanks to the API-First Initiative adding a normalizer to correctly and consistently normalize datetime information that we discovered this at all.
- Reported by @joelstein in #2926508-132: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON API.
- Root cause traced by @Wim Leers in #2926508-135: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON API.
- Confirmed by @mpdonadio in #2926508-139: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON API, and asked to be split to a separate issue. This is that separate issue.
Proposed resolution
Start specifying the timezone!
Expand test coverage: the existing test coverage was a low-level kernel test which specifically had a timezone offset specified (which was done explicitly for testing the TypedData aspects), but in reality datetime strings are stored in the database without timezone offsets (see @joelstein in #2926508-132: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON API).
Remaining tasks
Review.
User interface changes
None.
API changes
None. The \Drupal\Core\Datetime\DrupalDateTime
instance returned by \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()
now has the appropriate timezone set.
Data model changes
None.
BC implications
This patch changes nothing about current or future stored values. This only changes the mapping of stored values into DrupalDateTime
objects, which almost no code does (in core, only tests do this).