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

Datetime comparison bug with different timezones #158

Open
mobinghoveoud opened this issue Oct 25, 2024 · 1 comment · May be fixed by #159
Open

Datetime comparison bug with different timezones #158

mobinghoveoud opened this issue Oct 25, 2024 · 1 comment · May be fixed by #159
Labels

Comments

@mobinghoveoud
Copy link

mobinghoveoud commented Oct 25, 2024

Hi,

I ran into a problem while using jdatetime related to comparing datetimes. The issue happens when the timezones of the two datetime objects are different.

How to Reproduce the Issue:

code:

from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
import jdatetime

# python_datetime > jalali_datetime
python_datetime = datetime.now(ZoneInfo("UTC")) + timedelta(minutes=5)
jalali_datetime = jdatetime.datetime.now(ZoneInfo("Asia/Tehran"))

print(python_datetime)
print(jalali_datetime)
print(jalali_datetime >= python_datetime)
print(python_datetime <= jalali_datetime)

Output:

2024-10-25 17:25:22.215826+00:00
1403-08-04 20:50:22.215826+0330
True
True

The result should be False, but it shows True.

Proposed Solution:

I suggest changing the comparison methods in jdatetime.datetime to work like those in python datetime, so that timezone differences are considered. If this is acceptable, I would be happy to submit a pull request.
Thanks.


Runtime Information

  • jdatetime version: jdatetime-5.0.0
  • Python version: python 3.11
  • OS: Ubuntu
@mobinghoveoud mobinghoveoud changed the title Datetime omparison bug with different timezones Datetime comparison bug with different timezones Oct 25, 2024
@slashmili slashmili added the bug label Oct 25, 2024
@slashmili
Copy link
Owner

Hi @mobinghoveoud thanks for reporting the issue!

Yes, what you purposed makes sense, I missed that during the first implementation! a PR is welcome!

@mobinghoveoud mobinghoveoud linked a pull request Oct 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants