Skip to content

Commit

Permalink
System.ex monotonic_time/1 system_time/1
Browse files Browse the repository at this point in the history
Carbon copy from elixir with :native time unit removed, as it's not supported by current erlang implementation.

Signed-off-by: Peter M <petermm@gmail.com>
  • Loading branch information
petermm committed Sep 24, 2024
1 parent 5b6d8af commit 03ee764
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/exavmlib/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(ELIXIR_MODULES
Process
Protocol.UndefinedError
Range
System
Tuple

ArithmeticError
Expand Down
51 changes: 51 additions & 0 deletions libs/exavmlib/lib/System.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# This file is part of elixir-lang.
#
# Copyright 2012-2024 Elixir Contributors
# https://github.com/elixir-lang/elixir/blob/v1.17/lib/elixir/lib/system.ex
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

defmodule System do
@compile {:autoload, false}
@type time_unit ::
:second
| :millisecond
| :microsecond

@doc """
Returns the current monotonic time in the given time unit.
This time is monotonically increasing and starts in an unspecified
point in time.
"""
@spec monotonic_time(time_unit) :: integer
def monotonic_time(unit) do
:erlang.monotonic_time(unit)
end

@doc """
Returns the current system time in the given time unit.
It is the VM view of the `os_time/0`. They may not match in
case of time warps although the VM works towards aligning
them. This time is not monotonic.
"""
@spec system_time(time_unit) :: integer
def system_time(unit) do
:erlang.system_time(unit)
end
end

0 comments on commit 03ee764

Please sign in to comment.