oracle / graalpython

GraalPy – A high-performance embeddable Python 3 runtime for Java
https://www.graalvm.org/python/
Other
1.24k stars 108 forks source link

datetime mismatch due to wrong timezone #412

Closed lewurm closed 3 months ago

lewurm commented 3 months ago

Consider:

$ cat repro.py
import datetime
import time

def _get_unix_timestamp(day, month, year):
    dt = datetime.datetime(year = year, month = month, day = day)
    print(f"dt: {dt}")
    return dt.timestamp()

endDate = datetime.datetime.now()
print("unix timestamp: " + str(_get_unix_timestamp(endDate.day, endDate.month, endDate.year)))

print("mytz: " + "%+4.4d" % (time.timezone / -(60*60) * 100))

$ python3 --version; python3 repro.py
Python 3.12.4
dt: 2024-07-29 00:00:00
unix timestamp: 1722204000.0
mytz: +0100

$ ~/Downloads/graalpy-24.0.2-macos-aarch64/bin/graalpy --version; ~/Downloads/graalpy-24.0.2-macos-aarch64/bin/graalpy repro.py
GraalPy 3.10.13 (Oracle GraalVM Native 24.0.2)
dt: 2024-07-29 00:00:00
unix timestamp: 1722236400.0
mytz: -0800

$ ~/Downloads/graalpy-24.0.2-macos-aarch64/bin/graalpy-managed --version; ~/Downloads/graalpy-24.0.2-macos-aarch64/bin/graalpy-managed repro.py
GraalPy 3.10.13 (Oracle GraalVM Native 24.0.2)
dt: 2024-07-29 00:00:00
unix timestamp: 1722204000.0
mytz: +0100

something something native-image build-time I guess? 🙂

msimacek commented 3 months ago

Thank you for the reproducer, it is indeed build-time vs run-time issue

lewurm commented 3 months ago

Thanks for the quick fix 🙂