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 /lib/timeutils/timeutils.c | |
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 'lib/timeutils/timeutils.c')
-rw-r--r-- | lib/timeutils/timeutils.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index 77e5f043f1..94bdada980 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -73,6 +73,10 @@ void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, timeutils_struct_t mp_int_t days = seconds / 86400; seconds %= 86400; + if (seconds < 0) { + seconds += 86400; + days -= 1; + } tm->tm_hour = seconds / 3600; tm->tm_min = seconds / 60 % 60; tm->tm_sec = seconds % 60; |