diff options
author | Dave Hylands <dhylands@gmail.com> | 2015-05-18 08:26:58 -0700 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-05-21 23:31:50 +0300 |
commit | a3a14b9db79d3af24e724832092d1861ec231365 (patch) | |
tree | 500e393a3b73122a58fab32643514ba652120d5a /tests | |
parent | 6f1cffeb28c623e74d9914fe7dd16dc1494b5982 (diff) | |
download | micropython-a3a14b9db79d3af24e724832092d1861ec231365.tar.gz micropython-a3a14b9db79d3af24e724832092d1861ec231365.zip |
lib: Fix some issues in timeutils
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pyb/modtime.py | 21 | ||||
-rw-r--r-- | tests/pyb/modtime.py.exp | 12 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/pyb/modtime.py b/tests/pyb/modtime.py index de6f8fbc6b..d45440a63c 100644 --- a/tests/pyb/modtime.py +++ b/tests/pyb/modtime.py @@ -35,4 +35,25 @@ def test(): yday += 1 wday = (wday + 1) % 7 +def spot_test(seconds, expected_time): + actual_time = time.localtime(seconds) + for i in range(len(actual_time)): + if actual_time[i] != expected_time[i]: + print("time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time) + return + print("time.localtime(", seconds, ") returned", actual_time, "(pass)") + + test() +spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1)) +spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1)) +spot_test( 59, (2000, 1, 1, 0, 0, 59, 5, 1)) +spot_test( 60, (2000, 1, 1, 0, 1, 0, 5, 1)) +spot_test( 3599, (2000, 1, 1, 0, 59, 59, 5, 1)) +spot_test( 3600, (2000, 1, 1, 1, 0, 0, 5, 1)) +spot_test( -1, (1999, 12, 31, 23, 59, 59, 4, 365)) +spot_test( 447549467, (2014, 3, 7, 23, 17, 47, 4, 66)) +spot_test( -940984933, (1970, 3, 7, 23, 17, 47, 5, 66)) +spot_test(-1072915199, (1966, 1, 1, 0, 0, 1, 5, 1)) +spot_test(-1072915200, (1966, 1, 1, 0, 0, 0, 5, 1)) +spot_test(-1072915201, (1965, 12, 31, 23, 59, 59, 4, 365)) diff --git a/tests/pyb/modtime.py.exp b/tests/pyb/modtime.py.exp index 0bf7c43f98..3e1f6e920c 100644 --- a/tests/pyb/modtime.py.exp +++ b/tests/pyb/modtime.py.exp @@ -32,3 +32,15 @@ Testing 2030 Testing 2031 Testing 2032 Testing 2033 +time.localtime( 0 ) returned (2000, 1, 1, 0, 0, 0, 5, 1) (pass) +time.localtime( 1 ) returned (2000, 1, 1, 0, 0, 1, 5, 1) (pass) +time.localtime( 59 ) returned (2000, 1, 1, 0, 0, 59, 5, 1) (pass) +time.localtime( 60 ) returned (2000, 1, 1, 0, 1, 0, 5, 1) (pass) +time.localtime( 3599 ) returned (2000, 1, 1, 0, 59, 59, 5, 1) (pass) +time.localtime( 3600 ) returned (2000, 1, 1, 1, 0, 0, 5, 1) (pass) +time.localtime( -1 ) returned (1999, 12, 31, 23, 59, 59, 4, 365) (pass) +time.localtime( 447549467 ) returned (2014, 3, 7, 23, 17, 47, 4, 66) (pass) +time.localtime( -940984933 ) returned (1970, 3, 7, 23, 17, 47, 5, 66) (pass) +time.localtime( -1072915199 ) returned (1966, 1, 1, 0, 0, 1, 5, 1) (pass) +time.localtime( -1072915200 ) returned (1966, 1, 1, 0, 0, 0, 5, 1) (pass) +time.localtime( -1072915201 ) returned (1965, 12, 31, 23, 59, 59, 4, 365) (pass) |