Dates without timezones

I’m defining the content model for an entry with a Date field. On the Appearance tab for the Date field, one of the choices for Format is “Date and time without timezone”. With this choice selected, the Content Delivery API returns a value like 2018-05-01T00:00 for the Date field.

According to ISO8601, omitting the timezone means “local time”. Is that how Contentful interprets these types of values when I search using the Content Delivery API? If so, “local time” where? If not, does Contentful treat these as UTC?

Also, if I want to search for all entries in May 2018, I could perform a search where date[gte]: 2018-05-01 and date[lt]: 2018-06-01 (I could also add times without timezones). What timezone would these use?

This matters because there are edge cases that depend on timezone interpretation: 2018-05-01T00:00 in my local time is 2018-04-30T23:00 UTC, so it’s ambiguous which month such a datetime belongs to: April or May.

PS I know “do everything in UTC” is the right approach generally, but these questions still need answers.

I made a content type with a date field, a datetime field, and a datetime with timezone field and made an entry like so:

Getting this from the API results in this:

"fields": {
    "name": "datetime test",
    "date": "2018-07-02",
    "datetime": "2018-07-02T12:00",
    "datetimeWithTimezone": "2018-07-02T12:00-07:00"

When you select the appearance “Date and time without timezone”, Contentful does not store any timezone data in the field. It is “local time” in every timezone so to speak.

When searching dates, Contentful is searching the string you provide as the search query against the string stored in the field value so searching for

date[gte]: 2018-05-01 and date[lt]: 2018-06-01

will match 2018-05-01T00:00 as well as 2018-05-01T00:00-07:00 as well as 2018-05-01T00:00+11:00

but won’t match 2018-04-30T00:00 as well as 2018-04-30T00:00-07:00 as well as 2018-04-30T00:00+11:00

In essence, Contentful is not doing any timezone interpretation. It is just storing the value as you give it and searching that string.

Can you try this?

  • Set the entry’s datetimeWithTimezone field to 2018-05-01T00:00:00+01:00
  • Search for datetimeWithTimezone[gte]: '2018-05-01T00:00:00Z', datetimeWithTimezone[lt]: '2018-06-01T00:00:00Z'

I think this was effectively the first iteration of my code. It didn’t find the entry, because in UTC the entry is in 2018-04-30. Changing the search months to 04 instead of 05 found the entry. This would suggest timezones are relevant in some way. Perhaps only if full ISO8601 datetimes are specified in the query?