Membrane Core v0.5.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.

Returns given milliseconds in internal Membrane time units.

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.

Returns given native units in internal Membrane time units.

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.

system_time() deprecated

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

Link to this section Functions

Returns given days in internal Membrane time units.

Inlined by the compiler.

The same as day/1.

Inlined by the compiler.

Link to this function

from_datetime(value)

View Source
from_datetime(DateTime.t()) :: t()

Converts DateTime to internal Membrane time units.

Inlined by the compiler.

Link to this function

from_iso8601!(value)

View Source
from_iso8601!(String.t()) :: t()

Converts iso8601 string to internal Membrane time units. If value is invalid, throws match error.

Inlined by the compiler.

Returns given hours in internal Membrane time units.

Inlined by the compiler.

The same as hour/1.

Inlined by the compiler.

Link to this macro

is_native_t(value)

View Source (macro)

Checks whether value is Membrane.Time.native_t

Checks whether value is Membrane.Time.t

Link to this function

microsecond(value)

View Source
microsecond(integer()) :: t()

Returns given microseconds in internal Membrane time units.

Inlined by the compiler.

Link to this function

microseconds(value)

View Source
microseconds(integer()) :: t()

The same as microsecond/1.

Inlined by the compiler.

Link to this function

millisecond(value)

View Source
millisecond(integer()) :: t()

Returns given milliseconds in internal Membrane time units.

Inlined by the compiler.

Link to this function

milliseconds(value)

View Source
milliseconds(integer()) :: t()

The same as millisecond/1.

Inlined by the compiler.

Link to this function

minute(value)

View Source
minute(integer()) :: t()

Returns given minutes in internal Membrane time units.

Inlined by the compiler.

Link to this function

minutes(value)

View Source
minutes(integer()) :: t()

The same as minute/1.

Inlined by the compiler.

Link to this function

monotonic_time()

View Source
monotonic_time() :: t()

Returns current monotonic time based on System.monotonic_time/0 in internal Membrane time units.

Inlined by the compiler.

Link to this function

nanosecond(value)

View Source
nanosecond(integer()) :: t()

Returns given nanoseconds in internal Membrane time units.

Inlined by the compiler.

Link to this function

nanoseconds(value)

View Source
nanoseconds(integer()) :: t()

The same as nanosecond/1.

Inlined by the compiler.

Link to this function

native_unit(value)

View Source
native_unit(native_t()) :: t()

Returns given native units in internal Membrane time units.

Inlined by the compiler.

Link to this function

native_units(value)

View Source
native_units(native_t()) :: t()

The same as native_unit/1.

Inlined by the compiler.

Link to this function

os_time()

View Source
os_time() :: t()

Returns current POSIX time of operating system in internal Membrane time units.

Inlined by the compiler.

Link to this function

pretty_duration(time)

View Source
pretty_duration(t()) :: String.t()

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"
Link to this function

pretty_now()

View Source
pretty_now() :: String.t()

Returns current time in pretty format (currently iso8601), as string Uses system_time/0 under the hood.

Link to this function

second(value)

View Source
second(integer()) :: t()

Returns given seconds in internal Membrane time units.

Inlined by the compiler.

Link to this function

seconds(value)

View Source
seconds(integer()) :: t()

The same as second/1.

Inlined by the compiler.

Link to this function

system_time()

View Source
system_time() :: t()
This function is deprecated. Use os_time/0 or vm_time/0 instead.

Returns current time of Erlang VM based on System.system_time/0 in internal Membrane time units.

Inlined by the compiler.

Link to this function

to_code(time)

View Source
to_code(t()) :: Macro.t()

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()
Link to this function

to_code_str(time)

View Source
to_code_str(t()) :: Macro.t()

Returns string representation of result of to_code/1.

Link to this function

to_datetime(value)

View Source
to_datetime(t()) :: DateTime.t()

Returns time as a DateTime struct. TimeZone is set to UTC.

Inlined by the compiler.

Link to this function

to_days(value)

View Source
to_days(t()) :: integer()

Returns time in days. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_hours(value)

View Source
to_hours(t()) :: integer()

Returns time in hours. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_iso8601(value)

View Source
to_iso8601(t()) :: String.t()

Returns time as a iso8601 string.

Inlined by the compiler.

Link to this function

to_microseconds(value)

View Source
to_microseconds(t()) :: integer()

Returns time in microseconds. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_milliseconds(value)

View Source
to_milliseconds(t()) :: integer()

Returns time in milliseconds. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_minutes(value)

View Source
to_minutes(t()) :: integer()

Returns time in minutes. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_nanoseconds(value)

View Source
to_nanoseconds(t()) :: integer()

Returns time in nanoseconds. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_native_units(value)

View Source
to_native_units(t()) :: native_t()

Returns time in system native units. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

to_seconds(value)

View Source
to_seconds(t()) :: integer()

Returns time in seconds. Rounded using Kernel.round/1

Inlined by the compiler.

Link to this function

vm_time()

View Source
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.