Timex.Time

Summary

abs(arg1)
add(arg1, arg2)
convert(timestamp, type \\ :timestamp)

Convert timestamp in the form { megasecs, seconds, microsecs } to the specified time units

days(value)
diff(t1, t2, type \\ :timestamp)

Time interval between two timestamps. If the first timestamp comes before the second one in time, the return value will be negative. Timestamp must be in format { megasecs, seconds, microseconds }

elapsed(timestamp, type \\ :timestamp)

Time interval between timestamp and now. If timestamp is after now in time, the return value will be negative. Timestamp must be in format { megasecs, seconds, microseconds }

elapsed(arg1, arg2, type)
epoch(type \\ :timestamp)

Return time interval since the first day of year 0 to Epoch

from(value, atom2)
hours(value)
invert(arg1)
measure(fun)
measure(fun, args)
measure(module, fun, args)
mins(value)
now(type \\ :timestamp)

Time interval since Epoch

scale(arg1, coef)
secs(value)
sub(arg1, arg2)
to_12hour_clock(hour)

Converts an hour between 0..24 to {1..12, :am/:pm}

to_24hour_clock(hour, am_or_pm)

Converts an hour between 1..12 in either am or pm, to value between 0..24

to_days(timestamp)
to_days(value, atom2)
to_hours(timestamp)
to_hours(value, atom2)
to_mins(timestamp)
to_mins(value, atom2)
to_msecs(ts)
to_msecs(value, atom2)
to_secs(ts)
to_secs(value, atom2)
to_timestamp(value, atom2)
to_usecs(arg1)
to_usecs(value, atom2)
to_weeks(timestamp)
to_weeks(value, atom2)
weeks(value)
zero()

Return a timestamp representing a time lapse of length 0

Functions

abs(arg1)
add(arg1, arg2)
convert(timestamp, type \\ :timestamp)

Convert timestamp in the form { megasecs, seconds, microsecs } to the specified time units.

Supported units: microseconds (:usecs), milliseconds (:msecs), seconds (:secs), minutes (:mins), hours (:hours), days (:days), or weeks (:weeks).

days(value)
diff(t1, t2, type \\ :timestamp)

Time interval between two timestamps. If the first timestamp comes before the second one in time, the return value will be negative. Timestamp must be in format { megasecs, seconds, microseconds }.

The third argument is an atom indicating the type of time units to return: microseconds (:usecs), milliseconds (:msecs), seconds (:secs), minutes (:mins), or hours (:hours).

When the third argument is omitted, the return value’s format is { megasecs, seconds, microsecs }.

elapsed(timestamp, type \\ :timestamp)

Time interval between timestamp and now. If timestamp is after now in time, the return value will be negative. Timestamp must be in format { megasecs, seconds, microseconds }.

The second argument is an atom indicating the type of time units to return: microseconds (:usecs), milliseconds (:msecs), seconds (:secs), minutes (:mins), or hours (:hours).

When the second argument is omitted, the return value’s format is { megasecs, seconds, microsecs }.

elapsed(arg1, arg2, type)
epoch(type \\ :timestamp)

Return time interval since the first day of year 0 to Epoch.

from(value, atom2)
hours(value)
invert(arg1)
measure(fun)
measure(fun, args)
measure(module, fun, args)
mins(value)
now(type \\ :timestamp)

Time interval since Epoch.

The argument is an atom indicating the type of time units to return (see convert/2 for supported values).

When the argument is omitted, the return value’s format is { megasecs, seconds, microsecs }.

scale(arg1, coef)
secs(value)
sub(arg1, arg2)
to_12hour_clock(hour)

Converts an hour between 0..24 to {1..12, :am/:pm}

Examples

iex> to_12hour_clock(23) {11, :pm}

to_24hour_clock(hour, am_or_pm)

Converts an hour between 1..12 in either am or pm, to value between 0..24

Examples

iex> to_24hour_clock(7, :pm) 19

to_days(timestamp)
to_days(value, atom2)
to_hours(timestamp)
to_hours(value, atom2)
to_mins(timestamp)
to_mins(value, atom2)
to_msecs(ts)
to_msecs(value, atom2)
to_secs(ts)
to_secs(value, atom2)
to_timestamp(value, atom2)
to_usecs(arg1)
to_usecs(value, atom2)
to_weeks(timestamp)
to_weeks(value, atom2)
weeks(value)
zero()

Return a timestamp representing a time lapse of length 0.

Time.convert(Time.zero, :secs) #=> 0

Can be useful for operations on collections of timestamps. For instance,

Enum.reduce timestamps, Time.zero, Time.add(&1, &2)