department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
281 stars 201 forks source link

Replace moment timezone adjustments with date-fns timezone helpers #22635

Open jbalboni opened 3 years ago

jbalboni commented 3 years ago

We should be able to replace uses of moment-timezone's .tz() helper in our application code and switch to the date-fns timezone helpers. Those helpers rely on polyfilled timezone data, so this should result in some reduction in bundle size for most users.

Important:

AC:

jbalboni commented 3 years ago

I'm moving this back to icebox, because I don't think it's worth switching our timezone handling code to use date-fns until their UTC handling improves, or we decide on a different option. The issues I ran into are:

  1. Because you're working with native JS Date objects, there's no easy way to put something in UTC mode. This means we can't easily both format something in a non-ISO format, as well as output it in UTC instead of local time, like we need for the calendar ICS file.
  2. Similarly, handling the weird Community Care date format is harder because we can't directly adjust the UTC offset, or parse the date in UTC mode. We have to parse it then add offsets for UTC and the local timezone.

This might get easier when we're using the vaos service and all start dates are coming through the same, but even then, the lack of UTC support is frustrating and leads to more confusing code. We can write helper functions for these issues, but those are likely to be error prone and easy to forget, for very little actual value right now.

Luxon or day.js seem better suited to us, and use the same polyfill for zones as date-fns, but I'm hesitant to try to get VSP to add a third date library to vets-website.

laurenernest commented 2 years ago

Create additional tickets to break up work as needed