-
Notifications
You must be signed in to change notification settings - Fork 21
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
How to interpret typed dates entered in simplified ISO 8601 format? #160
Comments
I think the use-utc seems kind of buggy. But for example if you have the date "2022-06-06" and use it in the js browser like this The best case is if we can achieve that no timezone is used at all. So that the user will always get the selected start of the day that the user selected. Which should be the case without |
I've spent quite a while looking into this and this is what I've found:
There are 4 props that allow you to input dates:
-> If
For example, if you type '01 Jan 2000', you will be entering a local date (so if you're in Germany, that means These issues arise not only when a user types dates into a One solution would be to forbid date strings and force developers to input their dates either as date objects, or timestamps. We would throw a descriptive error whenever a date string is found. Another solution may be to flag up any inconsistencies between date strings that have been inputted via props and the value of So, I think my preferred solution would be to simply ban people from entering date strings via the props! We should also add a section on 'UTC dates' in the documentation that clearly explains the need to input local dates when This doesn't solve the original issue of how to interpret dates that are typed into a @MrWook - your thoughts? |
Since writing this, I've softened my view on allowing date strings as props. After all, there's nothing that stops someone from changing this:
to this:
...so we may as well allow them. I do think it's important though to have some documentation that explains the difference between local dates and UTC dates to help prevent developers from making errors and I'll submit a PR for this shortly. The only thing that I'm unsure of now is whether we should also allow timestamps and date strings in the What do you think? |
When JavaScript parses dates, it assumes a timezone of UTC whenever it recognises a date string as being a simplification of the ISO 8601 format. e.g. '2000-01-01' is assumed to be in UTC timezone.
However, non-standard date strings are parsed using the browser's local timezone e.g. '1 January 2000' uses your browser's timezone. See example.
This begs the question as to how we should handle any such simplified ISO 8601 dates that a user may enter into a typeable datepicker...
Assuming
use-utc
is false, should we:a) Continue with the existing behaviour and allow users to be potentially baffled as to why when they enter a date such as '2000-01-01', depending on their browser's timezone, the datepicker actually selects a date representing the previous day?
b) Try to catch any dates a user enters that the browser may interpret as being in simplified ISO 8601 format and convert them to a local timezone date instead?
Similarly in the scenario where
use-utc
is true, should we interpret all typed dates as being in UTC timezone, including those which would normally be parsed using the browser's local timezone such as '1 January 2000'?A further complication:
What about if the user actually specifies a timezone e.g. '1 January 2000 EST' or '2000-01-01T00:00:00.000-05:00'? Should we use it, or not? If we do, we'd need to run all typed dates against a regex to determine whether or not a timezone has been added - and while the
[+-]hh:mm
scenario could be interpreted reasonably easily, it appears the three letter abbreviations are inconsistent e.g. does BST mean 'British Summer Time' or 'Bangladesh Standard Time'? The only ones I've found Chrome/Firefox to actually use are: UTC, GMT, EDT, EST, CDT, CST, MDT, MST, PDT and PST.The text was updated successfully, but these errors were encountered: