Membrane Core v0.5.2 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 time in days, represented as a rational number.

Returns time in hours, represented as a rational number.

Returns time in microseconds, represented as a rational number.

Returns time in milliseconds, represented as a rational number.

Returns time in minutes, represented as a rational number.

Returns time in nanoseconds, represented as a rational number.

Returns time in seconds, represented as a rational number.

Returns one day in Membrane.Time units.

day(number) deprecated

Returns given amount of days in Membrane.Time units.

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

Converts NTP timestamp (time since 0h on 1st Jan 1900) into Unix timestamp (time since 1st Jan 1970) represented in Membrane.Time units.

Returns one hour in Membrane.Time units.

hour(number) deprecated

Returns given amount of hours in Membrane.Time units.

is_t(value) deprecated

Checks whether a value is Membrane.Time.t.

Returns one microsecond in Membrane.Time units.

microsecond(number) deprecated

Returns given amount of microseconds in Membrane.Time units.

Returns one millisecond in Membrane.Time units.

millisecond(number) deprecated

Returns given amount of milliseconds in Membrane.Time units.

Returns one minute in Membrane.Time units.

minute(number) deprecated

Returns given amount of minutes in Membrane.Time units.

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

Returns one nanosecond in Membrane.Time units.

nanosecond(number) deprecated

Returns given amount of nanoseconds in Membrane.Time units.

Returns one VM native unit in Membrane.Time units.

native_unit(number) deprecated

Returns given amount of VM native units in Membrane.Time units.

Returns current POSIX time of operating system based on System.os_time/0 in 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 one second in Membrane.Time units.

second(number) deprecated

Returns given amount of seconds in Membrane.Time units.

system_time() deprecated

Returns current time of Erlang VM based on System.system_time/0 in 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 VM native units. Rounded using Kernel.round/1.

Converts the timestamp into NTP timestamp. May introduce small rounding errors.

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

Returns current Erlang VM system time based on System.system_time/0 in Membrane.Time units.

Link to this section Types

Link to this section Functions

Link to this function

as_days(time)

View Source
as_days(t()) :: integer() | Ratio.t()

Returns time in days, represented as a rational number.

Link to this function

as_hours(time)

View Source
as_hours(t()) :: integer() | Ratio.t()

Returns time in hours, represented as a rational number.

Link to this function

as_microseconds(time)

View Source
as_microseconds(t()) :: integer() | Ratio.t()

Returns time in microseconds, represented as a rational number.

Link to this function

as_milliseconds(time)

View Source
as_milliseconds(t()) :: integer() | Ratio.t()

Returns time in milliseconds, represented as a rational number.

Link to this function

as_minutes(time)

View Source
as_minutes(t()) :: integer() | Ratio.t()

Returns time in minutes, represented as a rational number.

Link to this function

as_nanoseconds(time)

View Source
as_nanoseconds(t()) :: integer() | Ratio.t()

Returns time in nanoseconds, represented as a rational number.

Link to this function

as_seconds(time)

View Source
as_seconds(t()) :: integer() | Ratio.t()

Returns time in seconds, represented as a rational number.

Returns one day in Membrane.Time units.

This function is deprecated. Use `day/0` or `days/1` instead..

Returns given amount of days in Membrane.Time units.

Link to this function

from_datetime(value)

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

Converts DateTime to Membrane.Time units.

Link to this function

from_iso8601!(value)

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

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

Link to this function

from_ntp_timestamp(arg)

View Source
from_ntp_timestamp(ntp_time :: <<_::64>>) :: t()

Converts NTP timestamp (time since 0h on 1st Jan 1900) into Unix timestamp (time since 1st Jan 1970) represented in Membrane.Time units.

NTP timestamp uses fixed point representation with the integer part in the first 32 bits and the fractional part in the last 32 bits.

Returns one hour in Membrane.Time units.

This function is deprecated. Use `hour/0` or `hours/1` instead..

Returns given amount of hours in Membrane.Time units.

This macro is deprecated. Use `is_time/1` instead.
Link to this macro

is_time(value)

View Source (macro)

Checks whether a value is Membrane.Time.t.

Link to this function

microsecond()

View Source
microsecond() :: t()

Returns one microsecond in Membrane.Time units.

Link to this function

microsecond(number)

View Source
microsecond(integer()) :: t()
This function is deprecated. Use `microsecond/0` or `microseconds/1` instead..
Link to this function

microseconds(number)

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

Returns given amount of microseconds in Membrane.Time units.

Link to this function

millisecond()

View Source
millisecond() :: t()

Returns one millisecond in Membrane.Time units.

Link to this function

millisecond(number)

View Source
millisecond(integer()) :: t()
This function is deprecated. Use `millisecond/0` or `milliseconds/1` instead..
Link to this function

milliseconds(number)

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

Returns given amount of milliseconds in Membrane.Time units.

Returns one minute in Membrane.Time units.

Link to this function

minute(number)

View Source
minute(integer()) :: t()
This function is deprecated. Use `minute/0` or `minutes/1` instead..
Link to this function

minutes(number)

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

Returns given amount of minutes in Membrane.Time units.

Link to this function

monotonic_time()

View Source
monotonic_time() :: t()

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

Link to this function

nanosecond()

View Source
nanosecond() :: t()

Returns one nanosecond in Membrane.Time units.

Link to this function

nanosecond(number)

View Source
nanosecond(integer()) :: t()
This function is deprecated. Use `nanosecond/0` or `nanoseconds/1` instead..
Link to this function

nanoseconds(number)

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

Returns given amount of nanoseconds in Membrane.Time units.

Link to this function

native_unit()

View Source
native_unit() :: t()

Returns one VM native unit in Membrane.Time units.

Link to this function

native_unit(number)

View Source
native_unit(integer()) :: t()
This function is deprecated. Use `native_unit/0` or `native_units/1` instead..
Link to this function

native_units(number)

View Source
native_units(integer()) :: t()

Returns given amount of VM native units in Membrane.Time units.

Link to this function

os_time()

View Source
os_time() :: t()

Returns current POSIX time of operating system based on System.os_time/0 in Membrane.Time units.

This time is not monotonic.

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.

Returns one second in Membrane.Time units.

Link to this function

second(number)

View Source
second(integer()) :: t()
This function is deprecated. Use `second/0` or `seconds/1` instead..
Link to this function

seconds(number)

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

Returns given amount of seconds in Membrane.Time units.

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 Membrane.Time units.

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 Membrane.Time.minute() 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.

Link to this function

to_days(time)

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

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

Link to this function

to_hours(time)

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

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

Link to this function

to_iso8601(value)

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

Returns time as a iso8601 string.

Link to this function

to_microseconds(time)

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

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

Link to this function

to_milliseconds(time)

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

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

Link to this function

to_minutes(time)

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

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

Link to this function

to_nanoseconds(time)

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

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

Link to this function

to_native_units(value)

View Source
to_native_units(t()) :: integer()

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

Link to this function

to_ntp_timestamp(timestamp)

View Source
to_ntp_timestamp(timestamp :: t()) :: <<_::64>>

Converts the timestamp into NTP timestamp. May introduce small rounding errors.

Link to this function

to_seconds(time)

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

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

Link to this function

vm_time()

View Source
vm_time() :: t()

Returns current Erlang VM system time based on System.system_time/0 in 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.