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

naive DateTime.diff fails when the input is a naive datetime object, as pendulum.instance converts it to a pendulum.DateTime with UTC tz #880

Open
2 tasks done
NodeJSmith opened this issue Mar 12, 2025 · 0 comments

Comments

@NodeJSmith
Copy link

  • 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: Ubuntu 22.04.3 LTS (running in WSL2)

  • Pendulum version: 3.0.0

Issue

When a naive pendulum.DateTime calls diff with a stdlib datetime object the input is converted to a pendulum instance, but it defaults to having a timezone of UTC, causing a TypeError

TypeError: can't compare offset-naive and offset-aware datetimes

Repro

from datetime import datetime

import pendulum

pendulum_today = pendulum.today().naive()
stdlib_today = datetime.today()

print(pendulum_today.tzinfo)
print(stdlib_today.tzinfo)

pendulum_today.diff(stdlib_today)
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

1 participant