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

Don't ignore days in timedelta when converting to TimeZone #360

Merged

Conversation

JaroslavTulach
Copy link
Contributor

Trying to create a date in US/New_York timezone and convert it into Java fails. This was reported to Enso by our US based developer: enso-org/enso#7655 - the final exception is:

Execution finished with an error: java.time.DateTimeException: Zone offset not in valid range: -18:00 to +18:00
        at <java> java.base/java.time.ZoneOffset.ofTotalSeconds(ZoneOffset.java:417)
        at <java> com.oracle.graal.python.builtins.objects.PythonAbstractObject.createZoneId(PythonAbstractObject.java:1001)
        at <java> com.oracle.graal.python.builtins.objects.PythonAbstractObject.asTimeZone(PythonAbstractObject.java:949)

I have investigated the issue and I am providing a test to simulate the problem as well as a possible fix. the issue is that running:

from datetime import timedelta, datetime, timezone

zone = timezone(timedelta(seconds=-18000), "US/Eastern")
dt = datetime(1970, 1, 1, 0, 0, 1, tzinfo=zone)


print(dt)
print(dt.tzinfo)
print(dt.tzinfo.utcoffset(dt).seconds)

dt.tzinfo

yields

1970-01-01 00:00:01-05:00
US/Eastern
68400

e.g. the value of seconds field is bigger than allowed -18:00 and +18:00. My fix also reads value of days which is (in this case) -1 and compensates the value to fit into the desired range.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants