Membrane Core v0.3.0 Membrane.Time View Source
Module containing functions needed to perform handling of time.
Membrane always internally uses nanosecond as a time unit. This is how all time units should represented in the code unless there's a good reason to act differently.
Please note that Erlang VM may internally use different units and that may differ from platform to platform. Still, unless you need to perform calculations that do not touch hardware clock, you should use Membrane units for consistency.
Link to this section Summary
Functions
Returns given days in internal Membrane time units
The same as day/1
Converts DateTime
to internal Membrane time units
Converts iso8601 string to internal Membrane time units.
If value
is invalid, throws match error
Returns given hours in internal Membrane time units
The same as hour/1
Checks whether value is Membrane.Time.native_t
Checks whether value is Membrane.Time.t
Returns given microseconds in internal Membrane time units
The same as microsecond/1
Returns given milliseconds in internal Membrane time units
The same as millisecond/1
Returns given minutes in internal Membrane time units
The same as minute/1
Returns current monotonic time based on System.monotonic_time/0
in internal Membrane time units
Returns given nanoseconds in internal Membrane time units
The same as nanosecond/1
Returns given native units in internal Membrane time units
The same as native_unit/1
Returns current POSIX time of operating system in internal Membrane time units
Returns duration as a string with unit. Chosen unit is the biggest possible that doesn't involve precission loss
Returns current time in pretty format (currently iso8601), as string
Uses system_time/0
under the hood
Returns given seconds in internal Membrane time units
The same as second/1
Returns current time of Erlang VM based on System.system_time/0
in internal Membrane time units
Returns quoted code producing given amount time. Chosen unit is the biggest possible that doesn't involve precission loss
Returns string representation of result of to_code/1
Returns time as a DateTime
struct. TimeZone is set to UTC
Returns time in days. Rounded using Kernel.round/1
Returns time in hours. Rounded using Kernel.round/1
Returns time as a iso8601 string
Returns time in microseconds. Rounded using Kernel.round/1
Returns time in milliseconds. Rounded using Kernel.round/1
Returns time in minutes. Rounded using Kernel.round/1
Returns time in nanoseconds. Rounded using Kernel.round/1
Returns time in system native units. Rounded using Kernel.round/1
Returns time in seconds. Rounded using Kernel.round/1
Returns current Erlang VM system time based on System.system_time/0
in internal Membrane time units
Link to this section Types
native_t()
View Source
native_t() :: integer()
native_t() :: integer()
non_neg_t()
View Source
non_neg_t() :: non_neg_integer()
non_neg_t() :: non_neg_integer()
t()
View Source
t() :: integer()
t() :: integer()
Link to this section Functions
day(value) View Source
Returns given days in internal Membrane time units.
Inlined by the compiler.
days(value) View Source
The same as day/1
.
Inlined by the compiler.
from_datetime(value)
View Source
from_datetime(DateTime.t()) :: t()
from_datetime(DateTime.t()) :: t()
Converts DateTime
to internal Membrane time units.
Inlined by the compiler.
from_iso8601!(value) View Source
Converts iso8601 string to internal Membrane time units.
If value
is invalid, throws match error.
Inlined by the compiler.
hour(value) View Source
Returns given hours in internal Membrane time units.
Inlined by the compiler.
hours(value) View Source
The same as hour/1
.
Inlined by the compiler.
is_native_t(value) View Source (macro)
Checks whether value is Membrane.Time.native_t
is_t(value) View Source (macro)
Checks whether value is Membrane.Time.t
microsecond(value) View Source
Returns given microseconds in internal Membrane time units.
Inlined by the compiler.
microseconds(value) View Source
The same as microsecond/1
.
Inlined by the compiler.
millisecond(value) View Source
Returns given milliseconds in internal Membrane time units.
Inlined by the compiler.
milliseconds(value) View Source
The same as millisecond/1
.
Inlined by the compiler.
minute(value) View Source
Returns given minutes in internal Membrane time units.
Inlined by the compiler.
minutes(value) View Source
The same as minute/1
.
Inlined by the compiler.
monotonic_time()
View Source
monotonic_time() :: t()
monotonic_time() :: t()
Returns current monotonic time based on System.monotonic_time/0
in internal Membrane time units.
Inlined by the compiler.
nanosecond(value) View Source
Returns given nanoseconds in internal Membrane time units.
Inlined by the compiler.
nanoseconds(value) View Source
The same as nanosecond/1
.
Inlined by the compiler.
native_unit(value) View Source
Returns given native units in internal Membrane time units.
Inlined by the compiler.
native_units(value) View Source
The same as native_unit/1
.
Inlined by the compiler.
os_time()
View Source
os_time() :: t()
os_time() :: t()
Returns current POSIX time of operating system in internal Membrane time units.
Inlined by the compiler.
pretty_duration(time) View Source
Returns duration as a string with unit. Chosen unit is the biggest possible that doesn't involve precission loss.
Examples
iex> import Membrane.Time
iex> 10 |> milliseconds() |> pretty_duration()
"10 ms"
iex> 60_000_000 |> microseconds() |> pretty_duration()
"1 min"
iex> 2 |> nanoseconds() |> pretty_duration()
"2 ns"
pretty_now()
View Source
pretty_now() :: String.t()
pretty_now() :: String.t()
Returns current time in pretty format (currently iso8601), as string
Uses system_time/0
under the hood.
second(value) View Source
Returns given seconds in internal Membrane time units.
Inlined by the compiler.
seconds(value) View Source
The same as second/1
.
Inlined by the compiler.
system_time()
View Source
system_time() :: t()
system_time() :: t()
Returns current time of Erlang VM based on System.system_time/0
in internal Membrane time units.
Inlined by the compiler.
to_code(time) View Source
Returns quoted code producing given amount time. Chosen unit is the biggest possible that doesn't involve precission loss.
Examples
iex> import Membrane.Time
iex> 10 |> milliseconds() |> to_code() |> Macro.to_string()
quote do 10 |> Membrane.Time.milliseconds() end |> Macro.to_string()
iex> 60_000_000 |> microseconds() |> to_code() |> Macro.to_string()
quote do 1 |> Membrane.Time.minutes() end |> Macro.to_string()
iex> 2 |> nanoseconds() |> to_code() |> Macro.to_string()
quote do 2 |> Membrane.Time.nanoseconds() end |> Macro.to_string()
to_code_str(time) View Source
Returns string representation of result of to_code/1
.
to_datetime(value)
View Source
to_datetime(t()) :: DateTime.t()
to_datetime(t()) :: DateTime.t()
Returns time as a DateTime
struct. TimeZone is set to UTC.
Inlined by the compiler.
to_days(value) View Source
Returns time in days. Rounded using Kernel.round/1
Inlined by the compiler.
to_hours(value) View Source
Returns time in hours. Rounded using Kernel.round/1
Inlined by the compiler.
to_iso8601(value) View Source
Returns time as a iso8601 string.
Inlined by the compiler.
to_microseconds(value) View Source
Returns time in microseconds. Rounded using Kernel.round/1
Inlined by the compiler.
to_milliseconds(value) View Source
Returns time in milliseconds. Rounded using Kernel.round/1
Inlined by the compiler.
to_minutes(value) View Source
Returns time in minutes. Rounded using Kernel.round/1
Inlined by the compiler.
to_nanoseconds(value) View Source
Returns time in nanoseconds. Rounded using Kernel.round/1
Inlined by the compiler.
to_native_units(value) View Source
Returns time in system native units. Rounded using Kernel.round/1
Inlined by the compiler.
to_seconds(value) View Source
Returns time in seconds. Rounded using Kernel.round/1
Inlined by the compiler.
vm_time()
View Source
vm_time() :: t()
vm_time() :: t()
Returns current Erlang VM system time based on System.system_time/0
in internal Membrane time units.
It is the VM view of the os_time/0
. They may not match in case of time warps.
It is not monotonic.
Inlined by the compiler.