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:
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.
pawan
(Pawan Rawal)
August 21, 2020, 7:01am
2
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?
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'
pawan
(Pawan Rawal)
August 21, 2020, 7:29am
4
abhijit-kar:
2019-09-18T19:00:52.23Z
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
mrjn
(Manish R Jain)
August 21, 2020, 8:51am
5
Why not just pass time in epoch seconds . Dgraph can take that as well.
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.
marsanaemi
(marsanaemi)
August 20, 2023, 11:51am
9
how did you use dayjs to convert date to rfc and from rfc to normal date?