pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

Comparing DateTimes before- and after-the-fold returns incorrect result

Open itaiperi opened this issue 1 year ago • 0 comments

  • [x] I am on the latest Pendulum version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: MacOS Sonoma 14.5
  • Pendulum version: 3.0.0

Issue

There's a problem when comparing dates which are in the same timezone, but have different offsets due to daylight savings in the fold. Basically, daylight savings are not taken into account in the fold. In the following example, d1 is after the fold, meaning it was 2:15 AM and was moved back to 1:15 AM, which should be after 1:25 AM before the fold. However, simply comparing d1 to d2 with d1 < d2 returns True, whereas d1.timestamp() < d2.timestamp() returns the correct result, False.

Example:

d1 = pendulum.datetime(2023, 11, 5, 1, 15, 0, 0, tz="America/Los_Angeles", fold=1)
d2 = pendulum.datetime(2023, 11, 5, 1, 25, 0, 0, tz="America/Los_Angeles", fold=0)

print(d1 < d2) # True
print(d1.timestamp() < d2.timestamp()) # False

itaiperi avatar Oct 30 '24 09:10 itaiperi