Skip to content

Commit 85d78df

Browse files
committed
Prefer native clock implementation if available
1 parent 363bf84 commit 85d78df

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

neo4j/time/clock_implementations.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ def utc_time(self):
4545
return ClockTime(seconds, nanoseconds * 1000)
4646

4747

48+
class PEP564Clock(Clock):
49+
""" Clock implementation based on the PEP564 additions to Python 3.7.
50+
This clock is guaranteed nanosecond precision.
51+
"""
52+
53+
@classmethod
54+
def precision(cls):
55+
return 9
56+
57+
@classmethod
58+
def available(cls):
59+
try:
60+
from time import time_ns
61+
except ImportError:
62+
return False
63+
else:
64+
return True
65+
66+
def utc_time(self):
67+
from time import time_ns
68+
t = time_ns()
69+
seconds, nanoseconds = divmod(t, 1000000000)
70+
return ClockTime(seconds, nanoseconds)
71+
72+
4873
class LibCClock(Clock):
4974
""" Clock implementation that works only on platforms that provide
5075
libc. This clock is guaranteed nanosecond precision.
@@ -79,28 +104,3 @@ def utc_time(self):
79104
return ClockTime(ts.seconds, ts.nanoseconds)
80105
else:
81106
raise RuntimeError("clock_gettime failed with status %d" % status)
82-
83-
84-
class PEP564Clock(Clock):
85-
""" Clock implementation based on the PEP564 additions to Python 3.7.
86-
This clock is guaranteed nanosecond precision.
87-
"""
88-
89-
@classmethod
90-
def precision(cls):
91-
return 9
92-
93-
@classmethod
94-
def available(cls):
95-
try:
96-
from time import time_ns
97-
except ImportError:
98-
return False
99-
else:
100-
return True
101-
102-
def utc_time(self):
103-
from time import time_ns
104-
t = time_ns()
105-
seconds, nanoseconds = divmod(t, 1000000000)
106-
return ClockTime(seconds, nanoseconds)

0 commit comments

Comments
 (0)