UnifiApi.Time (UnifiApi v0.4.0)

Copy Markdown View Source

Tiny time helpers for the v1 / v2 endpoints that take unix-millisecond timestamps (UnifiApi.Protect.Events.list/2 :start / :end, UnifiApi.Network.Traffic.by_client/3 :start / :end, etc.).

Saves the boilerplate System.os_time(:millisecond) - 60 * 60 * 1000 that every time-window query ends up needing.

Examples

import UnifiApi.Time

# Last hour of motion events
{:ok, events} =
  UnifiApi.Protect.Events.list(authed,
    start: hours_ago(1),
    end: now_ms(),
    types: ["motion"]
  )

Summary

Functions

Unix milliseconds for n days ago.

Unix milliseconds for n hours ago.

Unix milliseconds for n minutes ago. Accepts integers or floats.

Current time in unix milliseconds.

Functions

days_ago(n)

@spec days_ago(number()) :: integer()

Unix milliseconds for n days ago.

hours_ago(n)

@spec hours_ago(number()) :: integer()

Unix milliseconds for n hours ago.

minutes_ago(n)

@spec minutes_ago(number()) :: integer()

Unix milliseconds for n minutes ago. Accepts integers or floats.

now_ms()

@spec now_ms() :: integer()

Current time in unix milliseconds.