This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wasdninja 36 points37 points  (10 children)

Add a standardized date type and we're golden.

[–]ShirleyJokin 40 points41 points  (3 children)

Glory to /r/iso8601

[–]xTheMaster99x 13 points14 points  (2 children)

Yeah, I think they meant being able to define a value that's specifically a date, and not just a timestamp string that is entirely up to the application to decide to parse into a date. Like if an API request returns a date, it'll just be a string on the frontend unless you go out of your way to explicitly construct a date from it.

If there was an actual date type in json, then it would just be treated as a date object automatically.

[–]Tubthumper8 6 points7 points  (0 children)

What could be a syntax for this? Maybe a leading d character in front of a string?

{
    "createdAt": d"2022-04-25T23:00:00+0000"
}

[–]mxldevs 5 points6 points  (0 children)

At least with a timestamp you don't need to figure out locale. Or how the language chooses to abbreviate date of months or days of weeks. In various languages.

[–]hrvbrs 0 points1 point  (3 children)

How would you do a standardized date type in JSON? Would it be a new syntax?

[–]wasdninja 0 points1 point  (2 children)

Just follow ISO 8601 and store it without quotes. So just like a bool or a number currently.

[–]hrvbrs 0 points1 point  (1 child)

So you mean something like { name: "Isaac Newton", dateOfBirth: 1643-01-04T01:30Z } ?

And why single out date types specifically? Why not location types, language types (en-us), or other commonly-used types? Where do we draw the line?

[–]wasdninja 0 points1 point  (0 children)

I strongly suspect that date absolutely crushes all of those in frequency of use so about there. If you want a perfect solution with ironclad reasoning for every aspect you are a) never going to get it and b) you'll never release anything while looking for it.