RustPython / RustPython

A Python Interpreter written in Rust
https://rustpython.github.io
MIT License
19.09k stars 1.23k forks source link

datetime().astimezone() is broken #4982

Open xiaxinmeng opened 1 year ago

xiaxinmeng commented 1 year ago

It seems that RustPython supports datetime().astimezone() while the implementation of this function is broken and attribute 'tm_gmtoff' is missing. See the following example.

Example.py

from datetime import datetime
datetime(3001, 1, 19, 7, 59, 59, 999999).astimezone() 

Output on RustPython:

Traceback (most recent call last):
  File "/home/xxm/Desktop/RustPython/example.py", line 199, in <module>
    datetime(3001, 1, 19, 7, 59, 59, 999999).astimezone() 
  File "/home/xxm/.cargo/git/checkouts/rustpython-f8ef4d934ac33cd8/59df92d/pylib/Lib/datetime.py", line 1862, in astimezone
    tz = self._local_timezone()
  File "/home/xxm/.cargo/git/checkouts/rustpython-f8ef4d934ac33cd8/59df92d/pylib/Lib/datetime.py", line 1856, in _local_timezone
    gmtoff = localtm.tm_gmtoff
AttributeError: 'struct_time' object has no attribute 'tm_gmtoff'

Behavior on CPython: works normally

Environment: RustPython: v0.2.0 (https://github.com/RustPython/RustPython#59df92d7) CPython: 3.9.0 Ubuntu 18.04

DimitrisJim commented 1 year ago

both tm_gmtoff and tm_zone are missing from the struct_time struct:

https://github.com/RustPython/RustPython/blob/59df92d700fdf479b7294d44ff3f340ec9a0769c/vm/src/stdlib/time.rs#L318-L328

reference, Python docs on these: https://docs.python.org/3/library/time.html#time.struct_time

Might be easy to add them.