Add Safari compatibility - #73
Merged
Merged
Conversation
Contributor
|
Kind of wondering if there is a standard JS date library we can use |
Contributor
Author
|
Yeah, here are a few we may want to consider
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a browser supports an HTML
dateinput type, then the selected date will be presented to JS in the formYYYY-MM-DD. Safari does not have this UI, so instead the user is prompted to enter the date in that exact same format.However,
YYYY-MM-DDis not a format that the JavaScriptDateconstructor recognises in Safari (see Invalid Date in Safari on StackOverflow).Before passing the date (whether it came from the user or the UI) to the
Dateconstructor, this PR replaces all-symbols with/symbols. This is a format that Safari apparently recognises.I have tested on Chrome to make sure it continues to work - I expect most modern browsers should support
YYYY/MM/DDformat.Future work is to add validation to make sure that user inputs -- especially date inputs on Safari -- are actually valid dates. Part of that will be better error handling that will let the user know something went wrong. This is just a quick fix for Safari users but also any other browsers that don't support YYYY-MM-DD dates even if they do support the date picker UI.