aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/bif.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/bif.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/bif.c')
-rw-r--r--erts/emulator/beam/bif.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c
index 26f1b4facb..c3c247fffe 100644
--- a/erts/emulator/beam/bif.c
+++ b/erts/emulator/beam/bif.c
@@ -3385,6 +3385,70 @@ BIF_RETTYPE universaltime_to_localtime_1(BIF_ALIST_1)
BIF_RET(TUPLE2(hp, res1, res2));
}
+/* convert calendar:universaltime_to_seconds/1 */
+
+BIF_RETTYPE universaltime_to_seconds_1(BIF_ALIST_1)
+{
+ Sint year, month, day;
+ Sint hour, minute, second;
+
+ Sint64 seconds = 0;
+ Eterm *hp;
+ Uint hsz = 0;
+
+ if (!time_to_parts(BIF_ARG_1, &year, &month, &day,
+ &hour, &minute, &second))
+ BIF_ERROR(BIF_P, BADARG);
+
+ if (!univ_to_seconds(year, month, day, hour, minute, second, &seconds)) {
+ BIF_ERROR(BIF_P, BADARG);
+ }
+
+ erts_bld_sint64(NULL, &hsz, seconds);
+ hp = HAlloc(BIF_P, hsz);
+ BIF_RET(erts_bld_sint64(&hp, NULL, seconds));
+}
+
+/* convert calendar:seconds_to_universaltime/1 */
+
+BIF_RETTYPE seconds_to_universaltime_1(BIF_ALIST_1)
+{
+ Sint year, month, day;
+ Sint hour, minute, second;
+ Eterm res1, res2;
+ struct tm t;
+ Eterm* hp;
+
+ time_t seconds = 0;
+
+ if (is_not_integer(BIF_ARG_1)) {
+ BIF_ERROR(BIF_P, BADARG);
+ }
+
+ seconds = (time_t)signed_val(BIF_ARG_1);
+
+ if (!gmtime_r(&seconds, &t)) {
+ BIF_ERROR(BIF_P, BADARG);
+ }
+
+ year = t.tm_year + 1900;
+ month = t.tm_mon + 1;
+ day = t.tm_hour;
+ minute = t.tm_min;
+ second = t.tm_sec;
+ /* isdst = t.tm_isdst */
+
+ hp = HAlloc(BIF_P, 4+4+3);
+ res1 = TUPLE3(hp,make_small(year),make_small(month),
+ make_small(day));
+ hp += 4;
+ res2 = TUPLE3(hp,make_small(hour),make_small(minute),
+ make_small(second));
+ hp += 4;
+ BIF_RET(TUPLE2(hp, res1, res2));
+}
+
+
/**********************************************************************/