diff options
author | Björn-Egil Dahlberg <[email protected]> | 2011-12-06 02:55:13 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2011-12-08 14:12:02 +0100 |
commit | 8f36514229bfaaa6ede8a2daa6aa920686d4251f (patch) | |
tree | 9542b2b4182094c1a32e54ead33d4ae85b92e0b7 /erts/emulator/beam/erl_time_sup.c | |
parent | 469815129bd1ce53dc332d2c75142292e0604ef3 (diff) | |
download | otp-8f36514229bfaaa6ede8a2daa6aa920686d4251f.tar.gz otp-8f36514229bfaaa6ede8a2daa6aa920686d4251f.tar.bz2 otp-8f36514229bfaaa6ede8a2daa6aa920686d4251f.zip |
Remove OS taint from datetime conversion
Diffstat (limited to 'erts/emulator/beam/erl_time_sup.c')
-rw-r--r-- | erts/emulator/beam/erl_time_sup.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/erts/emulator/beam/erl_time_sup.c b/erts/emulator/beam/erl_time_sup.c index 00a4906caa..edf03d06fb 100644 --- a/erts/emulator/beam/erl_time_sup.c +++ b/erts/emulator/beam/erl_time_sup.c @@ -651,8 +651,34 @@ static time_t gregday(Sint year, Sint month, Sint day) #define SECONDS_PER_MINUTE (60) #define SECONDS_PER_HOUR (60 * SECONDS_PER_MINUTE) #define SECONDS_PER_DAY (24 * SECONDS_PER_HOUR) -#define SECONDS_PER_YEAR (86400) +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; + + *hour = secs / SECONDS_PER_HOUR; + *minute = tmp / SECONDS_PER_MINUTE; + *second = tmp % SECONDS_PER_MINUTE; + + days += 719468; + y = (10000*days + 14780) / 3652425; /* seriosly? */ + tmp = days - (365 * y + y/4 - y/100 + y/400); + + if (tmp < 0) { + y--; + tmp = days - (365*y + y/4 - y/100 + y/400); + } + mi = (100 * tmp + 52)/3060; + *month = (mi + 2) % 12 + 1; + *year = y + (mi + 2) / 12; + *day = tmp - (mi * 306 + 5)/10 + 1; + + return 1; +} int univ_to_seconds(Sint year, Sint month, Sint day, Sint hour, Sint minute, Sint second, Sint64 *time) { Sint days; |