Financial-Times / x-dash

:x::heavy_minus_sign::newspaper: shared front-end components for FT.com and the FT Apps
https://financial-times.github.io/x-dash
38 stars 6 forks source link

Update to date-fns version two #752

Closed benwallman closed 9 months ago

benwallman commented 9 months ago

Updated to date-fns version two. This was fairly tricky, I'd recommend TDD-ing future date util libraries as it will force simplicity.

A really nice feature of date-fns version 2 is that it stops you handling dates, numbers & strings interchangeably, and forces you to use either dates or numbers. This is much easier to grep, and they provide utility modules to get a dates format in whichever string you like.

The previous code has a hack in, which is to get the first 10 characters of a datestring and use that to get the date. This is not the correct behaviour, as timezones are a thing. I've kept that hack in one place, but have included a small comment for future maintainers.

If this is your first x-dash pull request please familiarise yourself with the contribution guide before submitting.

If you're creating a component: