~zulcss/cinder/cinder-ca-g2

« back to all changes in this revision

Viewing changes to cinder/openstack/common/timeutils.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman, Adam Gandelman, James Page
  • Date: 2012-11-01 11:30:15 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20121101113015-405w8kcosepo601w
Tags: 2013.1~g1~20121101.361-0ubuntu1
[ Adam Gandelman ]
* New upstream release.
* debian/patches/0001-Replace-builtin-hash.patch: Dropped.

[ James Page ]
* Cinder should suggest ceph-common, not python-ceph (LP: #1065901):
  - debian/control: cinder-volume Suggests: python-ceph -> ceph-common

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
 
64
64
def normalize_time(timestamp):
65
 
    """Normalize time in arbitrary timezone to UTC"""
 
65
    """Normalize time in arbitrary timezone to UTC naive object"""
66
66
    offset = timestamp.utcoffset()
67
 
    return timestamp.replace(tzinfo=None) - offset if offset else timestamp
 
67
    if offset is None:
 
68
        return timestamp
 
69
    return timestamp.replace(tzinfo=None) - offset
68
70
 
69
71
 
70
72
def is_older_than(before, seconds):
72
74
    return utcnow() - before > datetime.timedelta(seconds=seconds)
73
75
 
74
76
 
 
77
def is_newer_than(after, seconds):
 
78
    """Return True if after is newer than seconds."""
 
79
    return after - utcnow() > datetime.timedelta(seconds=seconds)
 
80
 
 
81
 
75
82
def utcnow_ts():
76
83
    """Timestamp version of our utcnow function."""
77
84
    return calendar.timegm(utcnow().timetuple())
121
128
 
122
129
def unmarshall_time(tyme):
123
130
    """Unmarshall a datetime dict."""
124
 
    return datetime.datetime(day=tyme['day'], month=tyme['month'],
125
 
                 year=tyme['year'], hour=tyme['hour'], minute=tyme['minute'],
126
 
                 second=tyme['second'], microsecond=tyme['microsecond'])
 
131
    return datetime.datetime(day=tyme['day'],
 
132
                             month=tyme['month'],
 
133
                             year=tyme['year'],
 
134
                             hour=tyme['hour'],
 
135
                             minute=tyme['minute'],
 
136
                             second=tyme['second'],
 
137
                             microsecond=tyme['microsecond'])