Skip to content

Provide default scalars for representing date/datetime in ISO format #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
excitement-engineer opened this issue Oct 30, 2016 · 15 comments

Comments

@excitement-engineer
Copy link
Contributor

excitement-engineer commented Oct 30, 2016

After having used graphql-js for some time I have had a lot of use-cases for scalars that represent a date and datetime. I was wondering what everyone's opinion is on including these convenience scalars in this project.

I realize that these scalars are not part of the graphql-spec and that different people use different date formats. However, I think that a lot of people will have a use case for these types of scalars. In addition, the ISO 8601 format is a very commonly accepted format for representing dates so it should be widely applicable.

I'm interest to hear your opinions on this matter!

@leebyron
Copy link
Contributor

leebyron commented Nov 1, 2016

We actually tossed around the idea of including a DateTime scalar in the spec, but decided to start conservatively. I like the idea of introducing an experimental one.

@excitement-engineer
Copy link
Contributor Author

I'd love to send a PR for an experimental datetime scalar that uses the ISO format! Is it okay if I implement this?

Did you guys also discuss including a date scalar (so without the time) in the spec?

@leebyron
Copy link
Contributor

leebyron commented Nov 1, 2016

DateTime should probably include Dates without Times, something the ISO format supports.

Feel free to start a PR if you're interested. We can take a look from there!

@excitement-engineer
Copy link
Contributor Author

Great, I will give it a try:) Thanks a lot for your help, I appreciate it!

@langpavel
Copy link
Contributor

Hi @leebyron and @excitement-engineer

History show us that there is no Date without (Time or Timezone)...

Most bad thing is date without explicit timezone.

All debates around with or without timezone are problematic because we all have local perception of spoken (=> written into form => stored in DB) time.

For me only acceptable format is timestamp expressed as number of (milli)seconds from (UNIX) big bang.

So, consider real number as one possible input for coercion..

I have something for this theme here: GraphQLTimestamp

@thebergamo
Copy link

I like the idea that GraphQL uses DateTime as default scalar, because in all systems, we'll need to express dates or just datetimes. Its a common problem, like using int, strings or whatever you want, so supporting this scalar at core is very important.

Of course, its not so simple as int or string, because is not a common use of it, but basically supporting the ISO date, you as a consumer of this scalar can easily parse all dates with momentjs ezpz without any problems.

Well, that's my 10cents!

@ebridges
Copy link

ebridges commented Aug 8, 2017

It is actually quite common to consider dates irrespective of a time zone: e.g. when listing holidays in a given year.

Requiring time (and timezones) to always be associated with a date (and vice versa) leads to inconvenient workarounds -- hence the ISO spec granting that flexibility.

GraphQL should support a scalar that simply represents an ISO8601 string. The implementing systems can easily parse any properly formatted string according to their needs (whether that be a Date, a Time, a DateTime, etc.).

If a system prefers to work in unix timestamps it's trivial to convert an ISO8601 to/from same.

@cloudlena
Copy link

Why not use RFC 3339?

@smithaitufe
Copy link

Please what is the state of this issue?
Has the date feature been implemented?
If so, where do I find the documentation?
If not, what is holding it back?

Thanks

@bygui86
Copy link

bygui86 commented Mar 25, 2018

+1

@langpavel
Copy link
Contributor

@smithaitufe See my comment. Date and time is not easy to express, it mostly depends on context.
Even same system may use different (storage) formats by semantics:

  • string representation
  • number representing UNIX epoch timestamp in seconds or milliseconds or even nanoseconds.
  • even something more customized

I'm using this custom scalar: GraphQLTimestamp

@langpavel
Copy link
Contributor

See also

@smithaitufe
Copy link

@langpavel

I ended up using that package as well and it has been working great.

@dandv
Copy link

dandv commented Jul 15, 2018

@langpavel: plans to make that gist into an easy-to-import npm package, like @excitement-engineer's grapql-iso-date? Or does that package already subsume yours?

@IvanGoncharov
Copy link
Member

I think Lee wrote great summary in #557:

I think the conclusion from this PR is that there is not one DateTime type to rule them all. Tradeoffs involved will lead to reasonable different decisions for different APIs.

Having these utility scalar types available in a package on NPM would be highly valuable, but since there isn't consensus on a single one, this package is probably the wrong place to host it. It's been incredibly valuable to work through this discussion in this forum!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants