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

Dane Powell created an issue. See original summary.

danepowell’s picture

Issue summary: View changes
e0ipso’s picture

I 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?

e0ipso’s picture

Status: Active » Postponed (maintainer needs more info)
danepowell’s picture

I'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-ff37f86db5ce

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

danepowell’s picture

Oh, 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)

wim leers’s picture

Title: Date fields missing time zones » [PP-1] Fields using the DateTimeIso8601 @DataType are missing an explicit time zone: missing a normalizer
Category: Support request » Task
Status: Postponed (maintainer needs more info) » Postponed
Issue tags: +API-First Initiative
Related issues: +#2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API
wim leers’s picture

wim leers’s picture