diff options
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/common/timeutils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index 8600439..4bf19a5 100644 --- a/openstack/common/timeutils.py +++ b/openstack/common/timeutils.py @@ -135,3 +135,16 @@ def unmarshall_time(tyme): minute=tyme['minute'], second=tyme['second'], microsecond=tyme['microsecond']) + + +def delta_seconds(before, after): + """ + Compute the difference in seconds between two date, time, or + datetime objects (as a float, to microsecond resolution). + """ + delta = after - before + try: + return delta.total_seconds() + except AttributeError: + return ((delta.days * 24 * 3600) + delta.seconds + + float(delta.microseconds) / (10 ** 6)) |
