date picker component: Updated function to accept more date formats #1040
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.
Requirements for adding, changing or removing a feature
Issue or RFC endorsed by the maintainers
Increase date formats which are supported 🎉
Description of the change
Added 3 new regular expressions for new formats:
yyyy-mm-dd
29 February 1980
29 Feb 80
29 Chwefror 1980
(Welsh)February 29, 1980
Chwefror 29ain, 1980
(Welsh)Amended the existing RegEx to:
29 / 02 /1980
)29 February, 1980
where there is a comma and space in one separator but not the other.Now, if any of these formats are used, the calendar will recognise the date if clicked open.
Alternative designs
I have tried to allow for all reasonable formats to be supported, to support copy-pasting of dates from anywhere into the input field.
Possible drawbacks
None unless I've made a mistake. The function is now more complex, has more regex etc. But the functionality of the date picker should not have been compromised in any way.
Verification process
We have a website which is using the date picker. I amended the code locally and tested it on that page. (Screenshot below - please ignore the slight colour differences, they are not part of this change.)
I tested it by typing in dates of various formats, and seeing whether the calendar recognised those dates by opening it and seeing that it defaulted to the date I had typed in. If it defaulted to today, then it hadn't recognised it.
I also typed in a number of dates which were in already-supported formats to ensure that these are still supported with the new code.
Release notes
Increase the number of accepted date formats to include 2-digit years and month names, including Welsh month names.