Prismic's Date API

Hello Prismic community,

I have a little technical question about Prismic's Date API. Actually we receive dates such as
"first_publication_date": "2020-09-01T09:39:51+0000",

The Date Time String format sent by Prismic is in The ISO8601 Basic format

The problem is that ECMAScript support the ISO8601 Extended format and not the Basic one therfore some browser like safari consider the basic format as invalid.

Calling new Date('2020-09-01T09:39:51+0000') in Safari throws an exception as an invalid Date while with chrome it works well!

ISO 8601 Extended Format is as follows: YYYY-MM-DDTHH:mm:ss.sssZZ is the time zone offset, specified as ā€œZā€ (for UTC) or either ā€œ+ā€ or ā€œ-ā€ followed by a time expression HH:mm

The difference between the extended notation and the basic notation is just the inclusion of the colon in the timezone offset value.

Is it possible to change the date format sent by prismic to be compatible ECMAScript ?


1 Like

Welcome to the community. I'm going to check this with my development team and get back to you ASAP.

Hello, I'm following up this with my development team. I need one information from you that what software are you using?

I'm calling Prismic GraphQL API on a React/React Native app

Test Environment :
Browser : Safari 13.0.3
OS : macOS Catalina 10.15.1

Hey @anas.khouja, thank you for your patience.

Nice catch regarding the date format sent by Prismic, indeed it does not comply with ECMAScript standard. This may be a legacy from our REST API originally being used by PHP, .NET, and other technologies.

Nowadays you're right most of our users may use our API through client-side or server-side JavaScript and this unconventional date format might be an issue there. We will consider updating our date format to comply with the extended ISO format ECMAScript wants but we'll also have to consider the potential breaking changes this implies.

Regarding your current issue, I suggest you to convert date in basic format coming from Prismic to extended format using a simple regex:

first_publication_date.replace(/(\+|-)(\d{2})(\d{2})$/, ".000$1$2:$3")

This will append .000 for milliseconds and convert +HHmm to +HH:mm.

Let us know if that solves your issue, happy to help more!


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.