I'm exporting a content type via Json API. This content type has a date and time field (field_test). I can input the date and time in the site timezone, and Json API renders it in UTC, as expected.
However, the datetime in the Json feed is lacking a timezone identifier, causing problems with relying application like Ember that assume datetimes are in a local timezone.
The field is output as:
"field_test": "2017-10-16T05:00:00"
I would expect something like this:
"field_test": "2017-10-16T05:00:00Z"
Note the ISO 8601 standard, which says that if a timezone identifier is lacking, the time should assumed to be local rather than UTC.
Not sure if this is a bug or misconfiguration, or possibly a problem with a component other than Json API. Please let me know if I should be looking in another direction.
Comments
Comment #2
danepowell commentedComment #3
e0ipsoI don't think JSON API does anything special to normalize datetime fields. Can you provide more information, like the call you are issuing to get the field?
Comment #4
e0ipsoComment #5
danepowell commentedI'm using a vanilla install of Lightning / Headless Lightning with the Lightning API module enabled. I don't think there's any specific configuration or handling of fields beyond what JSON API provides out of the box. I'm simply viewing the output of the entity at
jsonapi/node/foo/f26b215f-c11d-4135-9b35-ff37f86db5ceHow does JSON API determine in what format to render field values? I'm trying to figure out where exactly I can adjust the display of content via JSON API, or what needs to be patched to render dates correctly.
Comment #6
danepowell commentedOh, I think I understand. JSON API prints the raw field value, and in this case Drupal stores the date in UTC with no timezone identifier. I think this is a core bug: #2914779: Date field values are stored without timezone identifier
However, considering that that's unlikely to get fixed any time soon (if at all), can you recommend a way to work around this within JSON API? Would you recommend using JSON API Extras? (blocked by #2914781: Compatibility with Date range fields)
Comment #7
wim leersPer #2914779: Date field values are stored without timezone identifier — this is closely related to #2867206: API-First DX of "date" and "date range" fields: add 'datetime_iso8601' @DataType (de)normalizer using RFC3339 timestamps with timezones. But that still won't help JSON API until #2860350: Document why JSON API only supports @DataType-level normalizers is solved.
Comment #8
wim leersAs of #2867206-15: API-First DX of "date" and "date range" fields: add 'datetime_iso8601' @DataType (de)normalizer using RFC3339 timestamps with timezones, this is actively moving forward in Drupal core. Please help fix it there, so that Drupal 8.5 ships with the fix. That is now being fixed at #2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API.
Comment #9
wim leers#2926508-33: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API is fixing this.
Comment #10
wim leers#2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands now has a green patch — see #2929932-25: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands. It's blocked on #2955615: Field properties are not being denormalized, but that also has a green patch. So, this should soon be a problem of the past. Therefore finally marking this a duplicate, now that I'm very confident that it's being fixed!
And once #2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API lands, #2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands is obsolete. But by doing #2929932 in JSON API itself, we're no longer blocked on core's slower progress!
Comment #11
wim leers