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.
This commit is contained in:
committed by
Paul Sokolovsky
parent
6f1cffeb28
commit
a3a14b9db7
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user