-
Notifications
You must be signed in to change notification settings - Fork 429
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
Have we gotten the date type right? #79
Comments
Our current Disregarding our lacking documentation, this discussion comes down to wether or not we should include a
In addition to the current type, which is an object:
...amirite? If so, I'm all for implementing such a type, date picker and all! I think |
Yes!
Regardless of the choices we've already made, I still think its worth having a discussion about terminology, figure out how it should have been, and then explore whether its possible to fix it. If someone asked me to guess what type to use for a field to get a widget that gives me the value I think its very common to describe those as ISO-formatted date strings too. Also, I think its mildly confusing that this is what a date looks like:
...while this in contrast would be a value of some other type:
Ideally I'd like the type of the ISO date string to be named |
Just realized that Gradient uses |
After thinking about this for a few days, I tend to agree with @bjoerge - we should probably provide a simple I think we got a little caught up in trying to figure out how to do a proper date/time type that could cater to even advanced use cases that we forgot to factor in the difficulty of using it. With good documentation, we should be able to surface both types and the difference between them. |
Then everybody's all for a string-based Renaming the current date type: The only real hurdle would be to make/help users update their schemas and migrate all their I'm still of the opinion that Are you guys set on |
After a RL discussion we agree that we want two types for storing dates:
Can be configured in the schema to only store date (not time) information, in which case the time portion of the string is set to midnight, e.g.
The Questions in need of clarification:
|
Sounds good to me!
I think that makes sense. The default should be to display it in user (browser) timezone, but we could provide an option to specify that the date should be displayed in a specific timezone. Would that require including a timezone database? How do we deal with this today?
The more I think about this, the less I'm in favor of a storing a redundant |
We now have a Currently, both types can be configured to accept and store localized (e.g. 2017-02-21T10:15:00+01:00) or UTC (e.g. 2017-02-12T09:15:00Z) time using the Any thoughts on this? Other things to consider, but which will probably not cause breaking changes and can thus be postponed:
Here's the code, which should be production ready unless we want to change some behavior: |
After another RL discussion, we've agreed to roll with the above implementation. To summarize:
Up next:
|
For the record, Gradient issue on new handling of date strings here https://github.com/sanity-io/gradient/issues/402 |
Renamed to |
While working yesterday with importing data from firebase to Sanity, it struck me that our
date
-type has some issues wrt. developer ergonomics.When importing documents that already had several fields with unix timestamps, I had to convert all of them to objects of this shape before importing:
WHY do I need to store it like this?
TBH this felt like a violation of the easy things are easy-principle. There's probably a ton of cases where it makes perfectly good sense to store dates like this, but at least I'd like to know the reasoning behind it (documentation issue).
HOW do I format a date like this?
Do I need a timezone library? Have to drag in moment? Which fields here is absolutely required? What if I only have UTC date, do I need to add timezone still? What should that be, system timezone?
There are date fields on documents already (
_createdAt
,_updatedAt
). Of whattype
are these? Apparently notdate
.Sometimes you just want a field to be stored as a utc date (just like
_createdAt
, etc.), but we have no schema type for it. So: If I actually just want to store an utc date as a field (and still have it editable with a date picker in the studio), there's currently no way to do it.Additionally some queries ends up looking a bit awkward:
...and really easy to get wrong:
(this will not work as expected, nor return any errors telling you about your mistake!)
Possible solution
I think we should optimize for the most common use cases, but still support the less common (but nonetheless important) use cases.
We can do this by introduce a schema type for utc date strings (
date
,dateTime
,instant
?). My guess is that this would cover the majority of use cases involving dates. If one wants to preserve timezone information, we should provide a separate builtin schema type (maybezonedDateTime
?), which is an object that includes timezone information much like thedate
type we have today. (This data type could actually just be modelled by the schema author too, but I'm ok with making it a builtin type).Terminology
It may be a good idea try align our terminology as closely as possible to the current ECMAScript temporal proposal which is based on established terminology from years of accumulated experience from other programming languages:
https://github.com/maggiepint/proposal-temporal
Thoughs?
The text was updated successfully, but these errors were encountered: