Linux: Boottime API: User linux_constanst import

This commit is contained in:
Gustavo Moreira
2024-11-05 20:02:55 +11:00
parent 2efb4e7d28
commit c0fa2cfcd6
@@ -2217,12 +2217,12 @@ class Timespec64Abstract(abc.ABC):
# Based on ns_to_timespec64()
if nsec > 0:
tv_sec = nsec // NSEC_PER_SEC
tv_nsec = nsec % NSEC_PER_SEC
tv_sec = nsec // linux_constants.NSEC_PER_SEC
tv_nsec = nsec % linux_constants.NSEC_PER_SEC
elif nsec < 0:
tv_sec = -((-nsec - 1) // NSEC_PER_SEC) - 1
rem = (-nsec - 1) % NSEC_PER_SEC
tv_nsec = NSEC_PER_SEC - rem - 1
tv_sec = -((-nsec - 1) // linux_constants.NSEC_PER_SEC) - 1
rem = (-nsec - 1) % linux_constants.NSEC_PER_SEC
tv_nsec = linux_constants.NSEC_PER_SEC - rem - 1
else:
tv_sec = tv_nsec = 0
@@ -2233,13 +2233,15 @@ class Timespec64Abstract(abc.ABC):
# pylint: disable=E1101
return conversion.unixtime_to_datetime(
self.tv_sec + self.tv_nsec / NSEC_PER_SEC
self.tv_sec + self.tv_nsec / linux_constants.NSEC_PER_SEC
)
def to_timedelta(self) -> datetime.timedelta:
"""Converts this Timespec64Abstract subclass object to timedelta"""
# pylint: disable=E1101
return datetime.timedelta(seconds=self.tv_sec + self.tv_nsec / NSEC_PER_SEC)
return datetime.timedelta(
seconds=self.tv_sec + self.tv_nsec / linux_constants.NSEC_PER_SEC
)
def __add__(self, other) -> "Timespec64Concrete":
"""Returns a new Timespec64Concrete object that sums the current values with those
@@ -2282,12 +2284,12 @@ class Timespec64Abstract(abc.ABC):
# Based on kernel's set_normalized_timespec64()
# pylint: disable=E1101
while self.tv_nsec >= NSEC_PER_SEC:
self.tv_nsec -= NSEC_PER_SEC
while self.tv_nsec >= linux_constants.NSEC_PER_SEC:
self.tv_nsec -= linux_constants.NSEC_PER_SEC
self.tv_sec += 1
while self.tv_nsec < 0:
self.tv_nsec += NSEC_PER_SEC
self.tv_nsec += linux_constants.NSEC_PER_SEC
self.tv_sec -= 1