diff options
Diffstat (limited to 'openstack/common/timeutils.py')
| -rw-r--r-- | openstack/common/timeutils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index 4416a3b..ae300e4 100644 --- a/openstack/common/timeutils.py +++ b/openstack/common/timeutils.py @@ -106,3 +106,21 @@ def advance_time_seconds(seconds): def clear_time_override(): """Remove the overridden time.""" utcnow.override_time = None + + +def marshall_now(now=None): + """Make an rpc-safe datetime with microseconds. + + Note: tzinfo is stripped, but not required for relative times.""" + if not now: + now = utcnow() + return dict(day=now.day, month=now.month, year=now.year, hour=now.hour, + minute=now.minute, second=now.second, + microsecond=now.microsecond) + + +def unmarshall_time(tyme): + """Unmarshall a datetime dict.""" + return datetime.datetime(day=tyme['day'], month=tyme['month'], + year=tyme['year'], hour=tyme['hour'], minute=tyme['minute'], + second=tyme['second'], microsecond=tyme['microsecond']) |
