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

Bug to convert jalali to gegorian and again convert it to jalali #156

Open
vahidtwo opened this issue May 17, 2024 · 2 comments
Open

Bug to convert jalali to gegorian and again convert it to jalali #156

vahidtwo opened this issue May 17, 2024 · 2 comments

Comments

@vahidtwo
Copy link

Please include your runtime information

Hi i have AJIB issue
i try to use jdatetime to convert tehran jalali time to geogorian time (utc)
i wtite this code

tehran_timezone = pytz.timezone('Asia/Tehran')
z=jdatetime.datetime(1403, 2, 28, 15, 16, 13, tzinfo=tehran_timezone).togregorian().astimezone(tz=UTC)
jdatetime.datetime.fromgregorian(datetime=z).astimezone(tehran_timezone)
>>> jdatetime.datetime(1403, 2, 28, 15, 20, 13, 0, tzinfo=Asia/Tehran)

as u see the minute convert from 16 to 20
and it is a bug

  • jdatetime version:4.1.1
  • Python version:3.8
  • OS: debian
@5j9
Copy link
Contributor

5j9 commented May 18, 2024

I don't use pytz, but this could be a pytz issue because if you run the same code using datetime instead of jdatetime you'll get the same result.

If you can upgrade your Python, try using the zoneinfo module from the standard library, it was added in Python 3.9. It works as expected for me. Sample code:

import datetime
import pytz
from datetime import UTC
from zoneinfo import ZoneInfo


def try_tz(tehran_timezone):
    tehran_dt = datetime.datetime(2024, 2, 28, 15, 16, 13, tzinfo=tehran_timezone)
    print(tehran_dt)
    tehran_to_utc = tehran_dt.astimezone(UTC)
    print(tehran_to_utc)
    back_to_tehran = tehran_to_utc.astimezone(tehran_timezone)
    print(back_to_tehran)

try_tz(pytz.timezone("Asia/Tehran"))
print()
try_tz(ZoneInfo("Asia/Tehran"))

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