Skip to content

fix(GlDatepicker): fix date parsing when manually entering dates

What does this MR do?

Related to #1556 (closed)

Currently when you manually enter a date into the GlDatepicker input it subtracts a day from the date you entered. This is due to a quirk with JavaScript's Date.parse where dates with dashes are parsed differently than dates with slashes 🙄. See https://stackoverflow.com/a/31732581 for more information.

new Date("2011-09-24");
// => Fri Sep 23 2011 17:00:00 GMT-0700 (MST) - ONE DAY OFF.

new Date("2011/09/24");
// => Sat Sep 24 2011 00:00:00 GMT-0700 (MST) - CORRECT DATE.

This MR adds a custom parser to the Pikaday config to fix the issue.

Before After
Screen_Recording_2021-09-22_at_12.55.17_PM Screen_Recording_2021-09-27_at_1.40.13_PM

Does this MR meet the acceptance criteria?

Conformity

  • Code review guidelines.
  • GitLab UI's contributing guidlines.
  • [-] If it changes a Pajamas-compliant component's look & feel, the MR has been reviewed by a UX designer.
  • [-] If it changes GitLab UI's documentation guidelines, the MR has been reviewed by a Technical Writer.
  • If the MR changes a component's API, integration MR(s) have been opened in the following projects to ensure that the @gitlab/ui package can be upgraded quickly after the changes are released:
  • Added the ~"component:*" label(s) if applicable.
Edited by Peter Hegman

Merge request reports

Loading