marnusw / date-fns-tz

Complementary library for date-fns v2 adding IANA time zone support
MIT License
1.08k stars 116 forks source link

testing zonedTimeToUtc daylight saving jumps #220

Closed mcshaz closed 1 year ago

mcshaz commented 1 year ago

This adds 6 tests for daylight savings. It tests what is returned by zonedTimeToUtc when the zoned time argument is during the times the local clock is moved forward or backwards.

It serves two main purposes:

  1. Documenting behaviour for developers - for instance when a local time is repeated (the local clock has been turned backwards), the latter occurence is returned. This is perfectly useful behaviour, but the test serves to document it and ensure it remains consistent between updates.
  2. As per the comments in the test, there is a question of what to do when a zoned time is provided which does not exist - for example when the zoned clock jumps from 01:59 to 03:00. At present the UTC time coresponding to zoned time at 01:00 is returned in the test which sets the zoned time to 02:00. The tests pass at the moment with this behaviour. Ultimately I believe either an error should be thrown, or the first time after (in this example, the UTC time corresponding to 03:00 zoned) returned, but that is a slightly separate issue to this pull request.
marnusw commented 1 year ago

Thank you