Skip to content

Commit 95b8598

Browse files
committed
precision improvements
1 parent c48d865 commit 95b8598

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

servercom/timetools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Time(Immutable):
4040
@classmethod
4141
def set_unix_time(cls, unix_timestamp: int) -> None:
4242
cls._timeset = (int(monotonic()), int(unix_timestamp))
43-
cls._time_offset = int(unix_timestamp - monotonic())
43+
cls._time_offset = int(unix_timestamp - int(monotonic()))
4444

4545
@classmethod
4646
def set_time(cls, current_time: 'Time') -> None:
@@ -54,11 +54,13 @@ def from_unix_time(cls, unix_time: int) -> int:
5454
@classmethod
5555
def from_monotonic_time(cls, monotonic_time: int) -> int:
5656
"""Returns a UNIX timestamp for a given monotonic time"""
57-
return int(monotonic_time + cls._time_offset)
57+
if not isinstance(monotonic_time, int):
58+
raise TypeError("Monotonic time must be an integer")
59+
return monotonic_time + cls._time_offset
5860

5961
@classmethod
6062
def get_unix_time(cls) -> int:
61-
return cls.from_monotonic_time(monotonic())
63+
return cls.from_monotonic_time(int(monotonic()))
6264

6365
@classmethod
6466
def now(cls) -> 'Time':
@@ -195,4 +197,4 @@ def monotonic(self) -> int:
195197
"""Returns the equivalent monotonic time"""
196198
if self.absolute:
197199
return self.from_unix_time(self.seconds)
198-
return monotonic() + self.seconds
200+
return int(monotonic()) + self.seconds

0 commit comments

Comments
 (0)