Skip to content

Add newDate date utility function

Coung Ngo requested to merge cngo-add-newdate-function into master

What does this MR do and why?

This MR adds a new date function that basically wraps the Date constuctor to fix a bug when a date-only string yyyy-mm-dd is passed to Date constructor for users behind UTC. For example, the bug results in users in UTC-8 timezone getting a date that is 1 day behind:

new Date('2020-02-02')
// results in Sat Feb 01 2020 16:00:00 GMT-0800 (Pacific Standard Time)

From MDN:

When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as local time. This is due to a historical spec error that was not consistent with ISO 8601 but could not be changed due to web compatibility.

Sentry logging is also added to capture instances where date-only strings are passed to localeDateFormat so we can update theses instances to use newDate().

Follow-up MRs will:

  • Update our frontend guidelines to document this bug and spread awareness (then announce it on the frontend channel/call)
  • Replace newDateAsLocaleTime with this new date function as it does the same thing (I created the newDateAsLocaleTime function but hate the name!)

This is related to a recent regression !162274 (merged)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

How to set up and validate locally

  1. Set timezone of OS to one behind UTC, for example Sacramento California UTC-8 (on macos: System Settings > General > Date & Time > Closest city)
  2. Test by displaying the result of newDate('2022-02-02') anywhere in the UI.
Edited by Coung Ngo

Merge request reports

Loading