btrdb.utils.timez

Time related utilities

btrdb.utils.timez.currently_as_ns()

Returns the current UTC time as nanoseconds since epoch

btrdb.utils.timez.datetime_to_ns(dt)

Converts a datetime object to nanoseconds since epoch. If a timezone aware object is received then it will be converted to UTC.

Parameters:dt (datetime) –
Returns:nanoseconds
Return type:int
btrdb.utils.timez.ns_delta(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, nanoseconds=0)

Similar to timedelta, ns_delta represents a span of time but as the total number of nanoseconds.

Parameters:
  • days (int, float, decimal.Decimal) – days (as 24 hours) to convert to nanoseconds
  • hours (int, float, decimal.Decimal) – hours to convert to nanoseconds
  • minutes (int, float, decimal.Decimal) – minutes to convert to nanoseconds
  • seconds (int, float, decimal.Decimal) – seconds to convert to nanoseconds
  • milliseconds (int, float, decimal.Decimal) – milliseconds to convert to nanoseconds
  • microseconds (int, float, decimal.Decimal) – microseconds to convert to nanoseconds
  • nanoseconds (int) – nanoseconds to add to the time span
Returns:

amount of time in nanoseconds

Return type:

int

btrdb.utils.timez.ns_to_datetime(ns)

Converts nanoseconds to a datetime object (UTC)

Parameters:ns (int) – nanoseconds since epoch
Returns:nanoseconds since epoch as a datetime object
Return type:datetime
btrdb.utils.timez.to_nanoseconds(val)

Converts datetime, datetime64, float, str (RFC 2822) to nanoseconds. If a datetime-like object is received then nanoseconds since epoch is returned.

Parameters:val (datetime, datetime64, float, str) – an object to convert to nanoseconds
Returns:object converted to nanoseconds
Return type:int

Notes

The following string formats are supported for conversion.

Format String Description
%Y-%m-%d %H:%M:%S.%f%z RFC3339 format
%Y-%m-%d %H:%M:%S.%f RFC3339 with UTC default timezone
%Y-%m-%dT%H:%M:%S.%fZ JSON encoding, UTC timezone
%Y-%m-%dT%H:%M:%SZ JSON encoding, UTC timezone, without μs
%Y-%m-%dT%H:%M:%S.%f%z JSON-like encoding
%Y-%m-%dT%H:%M:%S.%f JSON-like encoding, UTC default timezone
%Y-%m-%d %H:%M:%S%z human readable date time with TZ
%Y-%m-%d %H:%M:%S human readable date time UTC default
%Y-%m-%d midnight at a particular date