Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timedelta additions to pendulum.DateTime #817

Open
2 tasks done
andreivnegrean opened this issue Apr 11, 2024 · 1 comment
Open
2 tasks done

timedelta additions to pendulum.DateTime #817

andreivnegrean opened this issue Apr 11, 2024 · 1 comment

Comments

@andreivnegrean
Copy link

andreivnegrean commented Apr 11, 2024

  • 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 13.2.1 (22D68)

  • Pendulum version: 3.0.0

Issue

Hi,

It seems like pendulum.DateTime additions of timedelta don't give the same result as in the case of pendulum.Duration additions when crossing a DST timezone boundary.

Examples:

assert DateTime(year=2024, month=11, day=3, hour=1, tzinfo=Timezone("America/Los_Angeles")) + timedelta(days=30) == DateTime(year=2024, month=12, day=3, hour=1, tzinfo=Timezone("America/Los_Angeles"))

throws the following:

AssertionError: assert DateTime(2024, 12, 3, 0, 0, 0, tzinfo=Timezone('America/Los_Angeles')) == DateTime(2024, 12, 3, 1, 0, 0, tzinfo=Timezone('America/Los_Angeles'))

the same assertion passes if adding a Duration instead of timedelta:

assert DateTime(year=2024, month=11, day=3, hour=1, tzinfo=Timezone("America/Los_Angeles")) + Duration(months=1) == DateTime(year=2024, month=12, day=3, hour=1, tzinfo=Timezone("America/Los_Angeles"))

The issue is also reproducible when adding weeks:

assert DateTime(year=2024, month=11, day=3, hour=1, tzinfo=Timezone("America/Los_Angeles")) + timedelta(weeks=1) == DateTime(year=2024, month=11, day=10, hour=1, tzinfo=Timezone("America/Los_Angeles"))
@ariebovenberg
Copy link

ariebovenberg commented Apr 11, 2024

I'm assuming this is because months in Duration is counted on the calendar (1am one month later is still 1am), while days in timedelta considers days to always be 24 hours (1am + 30×24h may not result in 1am again due to DST transitions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants