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

tests fail after 2038-01-10 #41

Closed
bmwiedemann opened this issue Sep 11, 2022 · 5 comments · Fixed by #42
Closed

tests fail after 2038-01-10 #41

bmwiedemann opened this issue Sep 11, 2022 · 5 comments · Fixed by #42

Comments

@bmwiedemann
Copy link

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

run tests on 2038-01-10
on openSUSE, I do

osc co openSUSE:Factory/python-DateTime && cd $_
osc build --vm-type=kvm --noservice --clean --build-opt=--vm-custom-opt="-rtc base=2038-01-10T00:00:00" --alternative-project=home:bmwiedemann:reproducible openSUSE_Tumbleweed

What I expect to happen:

tests should continue to pass in future

What actually happened:

3 tests failed:

     def testAddPrecision(self):  
         # Precision of serial additions
         dt = DateTime()          
 >       self.assertEqual(str(dt + 0.10 + 3.14 + 6.76 - 10), str(dt),
                          dt)              
 E       AssertionError: '2038/10/07 08:52:44.959838 UTC' != '2038/10/07 08:52:44.959840 UTC'    
 E       - 2038/10/07 08:52:44.959838 UTC
 E       ?                         ^^
 E       + 2038/10/07 08:52:44.959840 UTC
 E       ?                         ^^
 E        : 2038/10/07 08:52:44.959840 UTC

 FAILED src/DateTime/tests/test_datetime.py::DateTimeTests::testAddPrecision
 FAILED src/DateTime/tests/test_datetime.py::DateTimeTests::testConstructor4
 FAILED src/DateTime/tests/test_datetime.py::DateTimeTests::testSubtraction - ...

What version of Python and Zope/Addons I am using:

openSUSE-Tumbleweed 20220907
python-3.8

@d-maurer
Copy link
Contributor

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:

  1. ensure that your Python has not been compiled with -Ofast; if necessary, compile it yourself and ensure a proper CFLAGS
  2. perform the DateTime computation in a Python interpreter which only imports DateTime (and nothing else).

@bmwiedemann
Copy link
Author

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

@d-maurer
Copy link
Contributor

d-maurer commented Sep 13, 2022 via email

@icemac
Copy link
Member

icemac commented Sep 14, 2022

Just released the fix as https://pypi.org/project/DateTime/4.7/

@bmwiedemann
Copy link
Author

I verified, that it is indeed fixed in DateTime-4.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants