/usr/lib/python2.7/dist-packages/ooni/otime.py is in ooniprobe 1.3.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | from datetime import datetime, timedelta, tzinfo
class UTC(tzinfo):
"""UTC"""
ZERO = timedelta(0)
def utcoffset(self, dt):
return self.ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return self.ZERO
def prettyDateNow():
"""
Returns a good looking string for the local time.
"""
return datetime.now().ctime()
def utcPrettyDateNow():
"""
Returns a good looking string for utc time.
"""
return datetime.utcnow().ctime()
class InvalidTimestampFormat(Exception):
pass
def fromTimestamp(s):
"""
Converts a string that is output from the timestamp function back to a
datetime object
Args:
s (str): a ISO8601 formatted string.
ex. 1912-06-23T101234Z"
Note: we currently only support parsing strings that are generated from the
timestamp function and have no intention in supporting the full standard.
"""
try:
date_part, time_part = s.split('T')
hours, minutes, seconds = time_part[:2], time_part[2:4], time_part[4:6]
year, month, day = date_part.split('-')
except:
raise InvalidTimestampFormat(s)
return datetime(int(year), int(month), int(day), int(hours), int(minutes),
int(seconds))
def timestamp(t=None):
"""
The timestamp for ooni reports follows ISO 8601 in
UTC time format.
We do not inlcude ':' and include seconds.
Example:
if the current date is "10:12:34 AM, June 23 1912" (datetime(1912, 6,
23, 10, 12, 34))
the timestamp will be:
"1912-06-23T101234Z"
Args:
t (datetime): a datetime object representing the
time to be represented (*MUST* be expressed
in UTC).
If not specified will default to the current time
in UTC.
"""
if not t:
t = datetime.utcnow()
ISO8601 = "%Y-%m-%dT%H%M%SZ"
return t.strftime(ISO8601)
def epochToTimestamp(seconds):
return timestamp(datetime.fromtimestamp(seconds, UTC()))
def epochToUTC(seconds):
return float(datetime.utcfromtimestamp(seconds).strftime("%s"))
|