timeutils

Time related utilities and helper functions.

oslo_utils.timeutils.advance_time_delta(timedelta)

Advance overridden time using a datetime.timedelta.

oslo_utils.timeutils.advance_time_seconds(seconds)

Advance overridden time by seconds.

oslo_utils.timeutils.clear_time_override()

Remove the overridden time.

oslo_utils.timeutils.delta_seconds(before, after)

Return the difference between two timing objects.

Compute the difference in seconds between two date, time, or datetime objects (as a float, to microsecond resolution).

oslo_utils.timeutils.is_newer_than(after, seconds)

Return True if after is newer than seconds.

oslo_utils.timeutils.is_older_than(before, seconds)

Return True if before is older than seconds.

oslo_utils.timeutils.is_soon(dt, window)

Determines if time is going to happen in the next window seconds.

Parameters:
  • dt – the time
  • window – minimum seconds to remain to consider the time not soon
Returns:

True if expiration is within the given duration

oslo_utils.timeutils.iso8601_from_timestamp(timestamp)

Returns an iso8601 formatted date from timestamp.

oslo_utils.timeutils.isotime(at=None, subsecond=False)

Stringify time in ISO 8601 format.

oslo_utils.timeutils.marshall_now(now=None)

Make an rpc-safe datetime with microseconds.

Note: tzinfo is stripped, but not required for relative times.

oslo_utils.timeutils.normalize_time(timestamp)

Normalize time in arbitrary timezone to UTC naive object.

oslo_utils.timeutils.parse_isotime(timestr)

Parse time from ISO 8601 format.

oslo_utils.timeutils.parse_strtime(timestr, fmt='%Y-%m-%dT%H:%M:%S.%f')

Turn a formatted time back into a datetime.

oslo_utils.timeutils.set_time_override(override_time=None)

Overrides utils.utcnow.

Make it return a constant time or a list thereof, one at a time.

Parameters:override_time – datetime instance or list thereof. If not given, defaults to the current UTC time.
oslo_utils.timeutils.strtime(at=None, fmt='%Y-%m-%dT%H:%M:%S.%f')

Returns formatted utcnow.

oslo_utils.timeutils.total_seconds(delta)

Return the total seconds of datetime.timedelta object.

Compute total seconds of datetime.timedelta, datetime.timedelta doesn’t have method total_seconds in Python2.6, calculate it manually.

oslo_utils.timeutils.unmarshall_time(tyme)

Unmarshall a datetime dict.

oslo_utils.timeutils.utcnow()

Overridable version of utils.utcnow.

oslo_utils.timeutils.utcnow_ts()

Timestamp version of our utcnow function.

Previous topic

strutils

Next topic

units

This Page