Fixing the dependency on timezone attribute
* Fixing the dependency on timezone attribute
Timezone and timestamp() do not work on older versions of python. Removed this dependency.
* declared variable outside loop
resolved comments
@@ -160,6 +160,7 @@ class HostSnapshotter(object):
try:
if(responseBody != None):
json_reponseBody = json.loads(responseBody)
+ epochTime = datetime.datetime(1970, 1, 1, 0, 0, 0)
for snapshot_info in json_reponseBody['snapshotInfo']:
self.logger.log("From Host- IsSuccessful:{0}, SnapshotUri:{1}, ErrorMessage:{2}, StatusCode:{3}".format(snapshot_info['isSuccessful'], snapshot_info['snapshotUri'], snapshot_info['errorMessage'], snapshot_info['statusCode']))
@@ -171,9 +172,10 @@ class HostSnapshotter(object):
creationTimeObj = datetime.datetime.strptime(creationTimeString, "%Y-%m-%dT%H:%M:%S.%fZ")
except:
creationTimeObj = datetime.datetime.strptime(creationTimeString, "%Y-%m-%dT%H:%M:%SZ")
- creationTimeObj = creationTimeObj.replace(tzinfo=datetime.timezone.utc)
- creationTimeObj = str(round(creationTimeObj.timestamp()*1000))
- ddSnapshotIdentifierInfo = HostSnapshotObjects.DDSnapshotIdentifier(creationTimeObj , snapshot_info['ddSnapshotIdentifier']['id'], snapshot_info['ddSnapshotIdentifier']['token'])
+ self.logger.log("Converting the creationTime string received in UTC format to UTC Ticks")
+ timestamp = (creationTimeObj - epochTime).total_seconds()
+ creationTimeUTCTicks = str(int(timestamp * 1000))
+ ddSnapshotIdentifierInfo = HostSnapshotObjects.DDSnapshotIdentifier(creationTimeUTCTicks , snapshot_info['ddSnapshotIdentifier']['id'], snapshot_info['ddSnapshotIdentifier']['token'])
self.logger.log("ddSnapshotIdentifier Information from Host- creationTime : {0}, id : {1}".format(ddSnapshotIdentifierInfo.creationTime, ddSnapshotIdentifierInfo.id))
else:
self.logger.log("ddSnapshotIdentifier absent/None in Host Response")
