1.1.0版本
This commit is contained in:
64
UniTAP/common/timestamp.py
Normal file
64
UniTAP/common/timestamp.py
Normal file
@@ -0,0 +1,64 @@
|
||||
class Timestamp:
|
||||
|
||||
"""
|
||||
|
||||
Class contains information about timestamp in several representation variant:
|
||||
- Seconds `to_sec`.
|
||||
- Milliseconds `to_m_sec`.
|
||||
- Microseconds `to_u_sec`.
|
||||
- Nanoseconds `to_n_sec` or `value`.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, nano_secs: int):
|
||||
self.__value = nano_secs
|
||||
|
||||
@property
|
||||
def to_sec(self) -> float:
|
||||
"""
|
||||
Returns time in seconds.
|
||||
"""
|
||||
return self.__value / (10 ** 9)
|
||||
|
||||
@property
|
||||
def to_m_sec(self) -> float:
|
||||
"""
|
||||
Returns time milliseconds seconds.
|
||||
"""
|
||||
return self.__value / (10 ** 6)
|
||||
|
||||
@property
|
||||
def to_u_sec(self) -> float:
|
||||
"""
|
||||
Returns time microseconds seconds.
|
||||
"""
|
||||
return self.__value / (10 ** 3)
|
||||
|
||||
@property
|
||||
def to_n_sec(self) -> float:
|
||||
"""
|
||||
Returns time nanoseconds seconds.
|
||||
"""
|
||||
return self.__value
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
"""
|
||||
Returns time nanoseconds seconds.
|
||||
"""
|
||||
return self.__value
|
||||
|
||||
@value.setter
|
||||
def value(self, value: int):
|
||||
"""
|
||||
Set time in nanoseconds seconds.
|
||||
"""
|
||||
if value <= 0:
|
||||
raise ValueError(f"Value of timestamp cannot be less than 0.")
|
||||
self.__value = value
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.to_u_sec} milliseconds"
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__value == other.__value
|
||||
Reference in New Issue
Block a user