ariebovenberg / whenever

⏰ Sensible and typesafe datetimes for Python
https://whenever.rtfd.io
MIT License
361 stars 7 forks source link

error when accessing offset attribute of LocalDateTime #104

Closed detlefla closed 3 months ago

detlefla commented 3 months ago

A LocalDateTime object should either supply a valid .offset or refuse access to this attribute. It reports, however, a missing microseconds attribute. Example:

In [1]: from whenever import LocalSystemDateTime
In [2]: now = LocalSystemDateTime.now()
In [3]: now.offset
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
...
File /tmp/venv-we/lib/python3.12/site-packages/whenever/__init__.py:1019, in TimeDelta.from_py_timedelta(cls, td)
...
AttributeError: 'NoneType' object has no attribute 'microseconds'

It's actually possible though to obtain the offset through “naive” conversions:

In [4]: now.naive() - now.as_utc().naive()
Out[4]: TimeDelta(02:00:00)

Which is what I would expect from .offset in the first place – or an AttributeError for .offset.

ariebovenberg commented 3 months ago

@detlefla thanks for reporting, this is most definitely a bug. I'll get around to fixing this ASAP

ariebovenberg commented 3 months ago

I've found the cause of the problem and a fix will be out shortly

ariebovenberg commented 3 months ago

@detlefla release 0.5.1 is now out with the fix. 🙏 thanks for reporting this!