Skip to content

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

Open
@itaiperi

Description

@itaiperi
  • I am on the latest Pendulum version.
  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions