aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_time_sup.c
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2011-12-06 01:33:46 +0100
committerBjörn-Egil Dahlberg <[email protected]>2011-12-08 14:12:02 +0100
commit469815129bd1ce53dc332d2c75142292e0604ef3 (patch)
tree54781902dc4f2de4e4c662d9cf0f83a162f6bd8c /erts/emulator/beam/erl_time_sup.c
parentabaefc0452f5b40841562da0f215e7d1ac371f1b (diff)
downloadotp-469815129bd1ce53dc332d2c75142292e0604ef3.tar.gz
otp-469815129bd1ce53dc332d2c75142292e0604ef3.tar.bz2
otp-469815129bd1ce53dc332d2c75142292e0604ef3.zip
Add utc <-> seconds conversions bifs
Diffstat (limited to 'erts/emulator/beam/erl_time_sup.c')
-rw-r--r--erts/emulator/beam/erl_time_sup.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_time_sup.c b/erts/emulator/beam/erl_time_sup.c
index 695d08ae2d..00a4906caa 100644
--- a/erts/emulator/beam/erl_time_sup.c
+++ b/erts/emulator/beam/erl_time_sup.c
@@ -648,7 +648,36 @@ static time_t gregday(Sint year, Sint month, Sint day)
return ndays - 135140; /* 135140 = Jan 1, 1970 */
}
+#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 univ_to_seconds(Sint year, Sint month, Sint day, Sint hour, Sint minute, Sint second, Sint64 *time) {
+ Sint days;
+
+ if (!(IN_RANGE(1600, year, INT_MAX - 1) &&
+ IN_RANGE(1, month, 12) &&
+ IN_RANGE(1, day, (mdays[month] +
+ (month == 2
+ && (year % 4 == 0)
+ && (year % 100 != 0 || year % 400 == 0)))) &&
+ IN_RANGE(0, hour, 23) &&
+ IN_RANGE(0, minute, 59) &&
+ IN_RANGE(0, second, 59))) {
+ return 0;
+ }
+
+ days = gregday(year, month, day);
+ *time = SECONDS_PER_DAY;
+ *time *= days; /* don't try overflow it, it hurts */
+ *time += SECONDS_PER_HOUR * hour;
+ *time += SECONDS_PER_MINUTE * minute;
+ *time += second;
+ return 1;
+}
int
local_to_univ(Sint *year, Sint *month, Sint *day,