-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Build a "datetime + time zone" field type (LocalDateTime
?)
#2938
Comments
Just to expanding on this -- given that we'd (probably?) only want to store the date time (in UTC) and the time zone name, it would be possible to just have two separate fields (the Eg. if you're in San Fran and setting up an event in Sydney for Monday, Oct 5th at 6pm, you'd need to:
None of these are "easy to know". If we create a specialised field for this use case the user can enter the values in a much more intuitive way:
Easy! Likewise, when reading the value, having the |
To add to what @molomby mentioned
Notes:
|
@VinayaSathyanarayana, as far as I'm aware, Keystone doesn't make any assumptions about users so there's not really a built in concept of a |
@molomby While KeystoneJs does not current have the concept of |
The Temporal proposal is relevant to this.
|
See also the ECMAScript Internationalization API (Node.js docs). |
It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :) |
2022 April update – References here to the "current" implementation are talking about Keystone 5
DateTime
field type, not the Keystone 6timestamp
field type which is much more correct. Regardless, a field that stores a point in time (timestamp) and the time zone in which it should be rendered would still be useful. See #7327 for a more up to date discussion.As far as I can tell, the current
DateTime
type was built to solve the "always render as entered" problem:Where
DateTime
falls down is that it relies on the user knowing the offset of the time zone the event will be in, not just now but, at the time the event occurs. Sure, if I want to create the this event for May, I can enterMay 2nd at 6pm
. But, if I'm planning ahead, I can't just create another event forOct 5th at 6pm
; Oct 5th is the day after daylight savings kicks in and, if I don't realise that, the UTC date stored (once #2936 is fixed) will be for 7pm not 6pm.This is the same problem you'd have if you were creating an event from another time zone overseas. Arguably, the OS case is not as insidious though since you'd hopefully already realise you had to set correct the offset explicitly. (You'd still need to know what the correct offset was though.)
Interestingly, the way the
DateTime
type is built, this behaviour often doesn't cause problems. Even though enteringOct 5th at 6pm
in Sydney now will store the wrong UTC value (2020-10-05T08:00:00z
) it'll also store the wrong offset. When read back out by the field these errors cancel out.A better approach to the original problem is to store the time zone, not an offset. Eg.
Australia/Sydney
rather than+10
or+11
. This would allow Keystone to store correct UTC values while letting the user select from a friendly list, rather than know the correct offsets for their target time zones on the specific date.Implementation
I think, for this to work, the field type would expose 3 field:
2020-10-05T07:00:00z
)Australia/Sydney
)2020-10-05T18:00:00
)Note that all field could be read but, when creating or updating the value,
_local
and_utc
couldn't be set at the same time. I imagine, usually, the_timezone
and_local
values would be set (rather than_utc
) as they wouldn't require any time zone manipulation on the client.In terms of storage, only the
_utc
and_timezone
values would be needed. Sorting and comparison filters (ie.myDate_lt
,myDate_gte
, etc.) would be applied against the stored UTC value. I suppose the comparison filters could accept an ISO date string either with or without an offset (in which case they be assumed to be in the time zone stored).I'm hoping that, internally, this field type would leverage the
TimeZone
(#2937) andDateTimeUtc
field types. They're both useful on their own but packaging them together like this will allow a nicer experience for the Admin UI.I think that, once
LocalDateTime
type replacesDateTime
as the "always render as entered" solution, the currentDateTime
should be deprecated andDateTimeUtc
moved to core.The text was updated successfully, but these errors were encountered: