RFC 3339 format gave error, but ISO 8601 worked amicably!

I used rfc3999 function of date-fns package.

import { formatRFC3339 } from 'date-fns'

export function setup() {
  const born = formatRFC3339(new Date("1992/06/24"))
  const cakeDay = formatRFC3339(new Date())
}

Which I passed into a Mutation, but it resulted in following error:

Screenshot from 2020-08-20 20-00-18


However, the mutation succeeds when I used the Javascript’s inbuilt toISOString() which returns ISO 8601 formatted date.

export function setup() {
  const born = new Date("1992/06/24").toISOString()
  const cakeDay = new Date().toISOString()
}

I read time and again that RFC3339 format is supported and not ISO.

According to the Go standard lib, we expect RFC3339 time to be in this format

RFC3339     = "2006-01-02T15:04:05Z07:00"

Since the time that you specify doesn’t conform to the format you get an error. Is there an alternate layout that your library supports?

1 Like

No the library doesn’t have any other output for ISO 3339

// Represent 18 September 2019 in ISO 3339 format, 2 digits of second fraction:
const result = formatRFC3339(new Date(2019, 8, 18, 19, 0, 52, 234), { fractionDigits: 2 })
//=> '2019-09-18T19:00:52.23Z'

ISO 8601 is closest to what is expected by the backend.

// Represent 18 September 2019 in ISO 8601 format (UTC):
const result = formatISO(new Date(2019, 8, 18, 19, 0, 52))
//=> '2019-09-18T19:00:52Z'

This format works fine but is different from the one that you shared in the initial post above. See Go Playground - The Go Programming Language

Why not just pass time in epoch seconds . Dgraph can take that as well.

1 Like

I shared the format which gave error.

UTC is somewhat readable and I got acquainted with it.

Although there’s an awesome tiny library, ms by Vercel, to handle that format easily.

Somehow, while setting the date, the date format came out as
“1992-06-24T00:00:00+5.5:30”

Which gives error. I’ll have to check, why that was the case with the library.

P.S. Documentation for the date-fns library is wrong it seems.

I have raised a GitHub issue for the date-fns team.

And I found it better to use DayJS instead. It has 2kb footprint.

1 Like

how did you use dayjs to convert date to rfc and from rfc to normal date?