aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/gleam/os.gleam6
-rw-r--r--test/gleam/os_test.gleam12
3 files changed, 19 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 06389e9..3ea63f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
- The `result` module gains the `all` function.
- The `dynamic` module gains the `option` function.
- The `uri` module gains the `percent_encode` and `percent_decode` functions.
+- The `os` module gains the `erlang_timestamp` function.
## v0.11.0 - 2020-08-22
diff --git a/src/gleam/os.gleam b/src/gleam/os.gleam
index 0c3f38a..0623dd5 100644
--- a/src/gleam/os.gleam
+++ b/src/gleam/os.gleam
@@ -58,3 +58,9 @@ pub type TimeUnit {
/// https://erlang.org/doc/apps/erts/time_correction.html#OS_System_Time
pub external fn system_time(TimeUnit) -> Int =
"os" "system_time"
+
+/// Return the current OS system time as a tuple of Ints
+///
+/// http://erlang.org/doc/man/os.html#timestamp-0
+pub external fn erlang_timestamp() -> tuple(Int, Int, Int) =
+ "os" "timestamp"
diff --git a/test/gleam/os_test.gleam b/test/gleam/os_test.gleam
index 45fc0ef..815a9e0 100644
--- a/test/gleam/os_test.gleam
+++ b/test/gleam/os_test.gleam
@@ -26,3 +26,15 @@ pub fn system_time_test() {
{ os.system_time(os.Millisecond) < june_12_2020 * 1000000 }
|> should.equal(True)
}
+
+pub fn erlang_timestamp_test() {
+ // in microseconds
+ let june_12_2020 = 1591966971000000
+ let tuple(mega_seconds, seconds, micro_seconds) = os.erlang_timestamp()
+
+ let stamp_as_micro =
+ { mega_seconds * 1_000_000 + seconds } * 1_000_000 + micro_seconds
+
+ { stamp_as_micro > june_12_2020 }
+ |> should.be_true()
+}