Skip to content

Throw an error when formatDate's input is invalid

Paul Gascou-Vaillancourt requested to merge fix-format-date-safari-ff into master

Some context

While working on https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/13180 it appeared that, when the formatDate() utility receives a datetime string in yyyy-MM-dd HH:mm:ii format, it would fail to format the date on Safari and Firefox, causing a timeago component to not render in the project security dashboard.

Invalid date error in Safari

To fix the issue, it was necessary to ensure that the backend formats the date properly before it is handed to the frontend: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/13180#note_174326556

However, there's a good chance similar errors might go unnoticed because Chrome does not throw any error.

So what does this MR do?

To make sure we don't repeat this, this MR forces the formatDate() utility to throw an error whenever it receives an invalid datetime string.

Additionally:

  • datetime_utility_spec.js has been migrated from Karma to Jest

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

Edited by Paul Gascou-Vaillancourt

Merge request reports