forked from tqtezos/node-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utc-time-math.py
17 lines (13 loc) · 888 Bytes
/
utc-time-math.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
### Quick UTC time math script that calculates the difference in seconds between two timestamps
### Written by Luke Youngblood, [email protected]
import datetime
import sys
date_format = "%Y-%m-%dT%H:%M:%SZ"
response_timestamp = datetime.datetime.strptime(sys.argv[1], date_format)
current_timestamp = datetime.datetime.strptime(sys.argv[2], date_format)
if response_timestamp and current_timestamp and (current_timestamp - response_timestamp).total_seconds() <= float(sys.argv[3]):
print("Timestamp "+str(response_timestamp)+" is within "+sys.argv[3]+" seconds of "+str(current_timestamp)+" - delta is "+str((current_timestamp - response_timestamp).total_seconds()))
exit(0)
else:
print("Timestamp "+str(response_timestamp)+" is NOT within "+sys.argv[3]+" seconds of "+str(current_timestamp)+" - delta is "+str((current_timestamp - response_timestamp).total_seconds()))
exit(1)