Skip to content
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

date picker component: Updated function to accept more date formats #1040

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MalcolmVonMoJ
Copy link
Contributor

Requirements for adding, changing or removing a feature

  • Fill out the template below. Maintainers are free to close any pull requests that do not include enough information, at their discretion.
  • The pull request must contribute a change that has been endorsed by the maintainer team. See details in the template below.
  • The pull request must update the test suite to exercise the updated functionality.
  • After you create the pull request, all status checks must pass before a maintainer reviews your contribution.

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:

  • International format yyyy-mm-dd
  • Month names, e.g.
    • 29 February 1980
    • 29 Feb 80
    • 29 Chwefror 1980 (Welsh)
  • Leading month names, e.g.
    • February 29, 1980
    • Chwefror 29ain, 1980 (Welsh)

Amended the existing RegEx to:

  • Allow for inconsistent and longer separators (e.g. 29 / 02 /1980)
    • No change in the characters allowed to be separators, but this was necessary for the common format 29 February, 1980 where there is a comma and space in one separator but not the other.
  • Allow for 2 and 4 character years
    • Will assume the year is between 1970 & 2069 inclusively if a 2 digit year is used.

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.

image

Release notes

Increase the number of accepted date formats to include 2-digit years and month names, including Welsh month names.

@MalcolmVonMoJ MalcolmVonMoJ added the feature (improve) A task that improves an existing feature in the design system (inc. existing building blocks) label Dec 20, 2024
@MalcolmVonMoJ MalcolmVonMoJ requested a review from a team as a code owner December 20, 2024 16:53
@MalcolmVonMoJ MalcolmVonMoJ changed the title Updated function to accept more date formats date picker component: Updated function to accept more date formats Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature (improve) A task that improves an existing feature in the design system (inc. existing building blocks)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant