From ec0c88f4ef6ec02f3e3f2af7a6e4920cbdbfdfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 6 Dec 2011 13:13:37 +0100 Subject: Fix negative time in seconds_to_universaltime/1 --- erts/emulator/beam/erl_time_sup.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'erts/emulator') diff --git a/erts/emulator/beam/erl_time_sup.c b/erts/emulator/beam/erl_time_sup.c index edf03d06fb..54d732000b 100644 --- a/erts/emulator/beam/erl_time_sup.c +++ b/erts/emulator/beam/erl_time_sup.c @@ -655,17 +655,24 @@ static time_t gregday(Sint year, Sint month, Sint day) int seconds_to_univ(Sint64 time, Sint *year, Sint *month, Sint *day, Sint *hour, Sint *minute, Sint *second) { - Sint y,mi; - Sint64 days = time / SECONDS_PER_DAY; - Sint secs = time % SECONDS_PER_DAY; - Sint tmp = secs % SECONDS_PER_HOUR; + Sint y,mi; + Sint days = time / SECONDS_PER_DAY; + Sint secs = time % SECONDS_PER_DAY; + Sint tmp; + + if (secs < 0) { + days--; + secs += SECONDS_PER_DAY; + } + + tmp = secs % SECONDS_PER_HOUR; *hour = secs / SECONDS_PER_HOUR; *minute = tmp / SECONDS_PER_MINUTE; *second = tmp % SECONDS_PER_MINUTE; days += 719468; - y = (10000*days + 14780) / 3652425; /* seriosly? */ + y = (10000*((Sint64)days) + 14780) / 3652425; tmp = days - (365 * y + y/4 - y/100 + y/400); if (tmp < 0) { -- cgit v1.2.3