aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2011-12-06 13:13:37 +0100
committerBjörn-Egil Dahlberg <[email protected]>2011-12-08 14:12:02 +0100
commitec0c88f4ef6ec02f3e3f2af7a6e4920cbdbfdfa1 (patch)
tree4719d6ec37b7f655b21d52c882da8720cfcc2663 /erts/emulator/beam
parent8f36514229bfaaa6ede8a2daa6aa920686d4251f (diff)
downloadotp-ec0c88f4ef6ec02f3e3f2af7a6e4920cbdbfdfa1.tar.gz
otp-ec0c88f4ef6ec02f3e3f2af7a6e4920cbdbfdfa1.tar.bz2
otp-ec0c88f4ef6ec02f3e3f2af7a6e4920cbdbfdfa1.zip
Fix negative time in seconds_to_universaltime/1
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r--erts/emulator/beam/erl_time_sup.c17
1 files changed, 12 insertions, 5 deletions
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) {