Closed bmwiedemann closed 2 years ago
I tried to reproduce your problem and failed:
>>> from DateTime import DateTime
>>> dt=DateTime(2038, 10, 7,8,52,44.959838, "UTC")
>>> dt
DateTime('2038/10/07 08:52:44.959838 UTC')
>>> xdt = dt + 0.10 + 3.14 + 6.76 - 10
>>> xdt
DateTime('2038/10/07 08:52:44.959838 UTC')
>>> dt == xdt
True
Your observation is almost surely due to a rounding effect. Recently, rounding problems caused by a side effect of a compilation with the -Ofast
option have been discussed. DateTime
is not itself compiled but the side effects are (process) global and can effect rounding everywhere in the process.
At your place, I would:
-Ofast
; if necessary, compile it yourself and ensure a proper CFLAGS
DateTime
computation in a Python interpreter which only imports DateTime
(and nothing else).I found a reproducer:
from DateTime import DateTime
dt = DateTime(2038, 10, 7,8,52,44.959840, "UTC")
xdt = dt + 0.10 + 3.14 + 6.76 - 10
dt == xdt
Our CFLAGS contain -O2 and no -Ofast
Bernhard M. Wiedemann wrote at 2022-9-12 21:00 -0700:
I found a reproducer:
from DateTime import DateTime dt = DateTime(2038, 10, 7,8,52,44.959840, "UTC") xdt = dt + 0.10 + 3.14 + 6.76 - 10 dt == xdt
The error is located near the end of the _parse_args
method:
sc = round(sc, 6)
...
self._hour, self._minute, self._second = hr, mn, sc
...
if microsecs is None:
microsecs = long(math.floor(t * 1000000.0))
self._micros = microsecs
While the _second
computation rounds to the nearest microsecond,
the microsecond computation floors instead.
This leads to inconsistent _second
and _micros
values.
The __add__
implementation is based on _micros
. The error
happens due to an inconsistent _micros
value after the
+ 0.10
.
In addition, __add__
is somewhat suboptimal: it knows the
correct microsecond value but does not pass it; instead it
lets it be computed (wrongly) by _parse_args
.
Thank you for reporting this bug.
Just released the fix as https://pypi.org/project/DateTime/4.7/
I verified, that it is indeed fixed in DateTime-4.7.
BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)
What I did:
run tests on 2038-01-10 on openSUSE, I do
What I expect to happen:
tests should continue to pass in future
What actually happened:
3 tests failed:
What version of Python and Zope/Addons I am using:
openSUSE-Tumbleweed 20220907 python-3.8