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

lib/timeutils: Fix problem with dates prior to Mar 1, 2000 #1270

Closed
wants to merge 1 commit into from

Conversation

dhylands
Copy link
Contributor

The easiest way to see this is to do:

>>> import time
>>> time.localtime(0)
(2000, 1, 1, 0, 0, 0, 5, 1)
>>> time.localtime(1)
(2000, 1, 2, 233, 197, 197, 6, 2)

With this patch, we instead get:

>>> import time
>>> time.localtime(1)
(2000, 1, 1, 0, 0, 1, 5, 1)

Doh - In C % is NOT a modulo operator, it's a remainder operator.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 93.81% when pulling feee431 on dhylands:fix-timeutils into 97ce883 on micropython:master.

@pfalcon
Copy link
Contributor

pfalcon commented May 19, 2015

Can there be a testcase perhaps? Also, as a dumb sanity check style question - you don't need to check days for <0, no?

@dhylands
Copy link
Contributor Author

Sure - I'll fix the test code (in tests/pyb/modtime,py).

It currently passes the tests when seconds % 86400 == 0 (which it happens to in the test).

We should check the negative range (the test code currently tests only 2000..2034) which is the +ve range of 31 bit int. It can test the -ve range as well, and also test some offsets.

I think I'll just add some spot tests for the negative and positive side (the positive side exhaustively tests every day.

@pfalcon
Copy link
Contributor

pfalcon commented May 19, 2015

Yes, spot tests (within each distinct range/subset) is what we need, otherwise testsuite runs too long and people avoid running it ;-).

In particular, dates prior to Mar 1, 2000 are screwed up.

The easiest way to see this is to do:

>>> import time
>>> time.localtime(0)
(2000, 1, 1, 0, 0, 0, 5, 1)
>>> time.localtime(1)
(2000, 1, 2, 233, 197, 197, 6, 2)

With this patch, we instead get:
>>> import time
>>> time.localtime(1)
(2000, 1, 1, 0, 0, 1, 5, 1)

Doh - In C % is NOT a modulo operator, it's a remainder operator.
@dhylands
Copy link
Contributor Author

I added some spot-tests. Along the way, I discovered a bug in mktime. I'll deal with that in a separate PR.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 93.81% when pulling 14c28a3 on dhylands:fix-timeutils into 97ce883 on micropython:master.

@pfalcon
Copy link
Contributor

pfalcon commented May 21, 2015

Merged, thanks.

@pfalcon pfalcon closed this May 21, 2015
@dhylands dhylands deleted the fix-timeutils branch November 8, 2015 02:43
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 this pull request may close these issues.

None yet

3 participants