Utils unifi_video.utils

unifi_video.utils.dt_resolvable_to_ms(resolvable, utc_offset=0, resolution=60000.0)[source]

Convert datetime resolvable to milliseconds since the Unix epoch.

Parameters:
  • resolvable (datetime or int or str) – Object that is resolvable to a date and time (see below)
  • utc_offset (int) – UTC offset in seconds
  • resolution (int) – Max resolution (in ms) for the returned timestamp. Default is to mimic UniFi Video frontend in providing at most minute granularity.
Returns:

Milliseconds since the Unix epoch

Return type:

int

On datetime resolvables

The type of the resolvable parameter will affect the return value.

datetime: Naive datetime values are offset by utc_offset while TZ aware datetime values are offset by whatever timedelta their datetime.datetime.utcoffset() returns.

str: Strings are treated as naive datetime values and should follow ISO8601 in including at least the YYYY, MM, and DD parts in either YYYY-MM-DD or YYYYMMDD.

int: Ints are assumed to be UNIX timestamps; only ms conversion and granularity changes will be applied.

unifi_video.utils.parse_gmt_offset(gmt_hhmm)[source]

Parse UTC offset as reported by UniFi Video

Parameters:gmt_hhmm (str) – UTC offset from /bootstrap JSON (settings.systemSettings.gmtOffset)
Returns
int: UTC offset in seconds