lostcarpark / conclar

ConClár Programme Guide in ReactJS
MIT License
11 stars 12 forks source link

Use Temporal API for more robust date handling. #94

Closed lostcarpark closed 2 years ago

lostcarpark commented 2 years ago

This change uses the Temporal API, which is a proposed new date handling extension for JavaScript. As browsers don't yet support it, it has been added via the @js-temporal/polyfill library.

During processing, each program item has a dateAndTime field populated with is a Temporal.zonedDateTime field in the convention timezone. When displaying the output, can use the withTimeZone method to convert to the browser timezone, which cuts down the complexity of the code considerably.

It also converts the local and convention zonedDateTime values to PlainDate values. Comparing these lets us check if the item is on the previous or next day, and add a label accordingly.

I haven't looked at the code that checks if convention is currently ongoing, but I think this could also be considerably simplified.