Module csw.TMTTime
Classes
class TAITime (seconds: int, nanos: int)
-
Expand source code
@dataclass class TAITime(TMTTime): """ Creates a TAITime containing seconds since the epoch (1970) and the offset from seconds in nanoseconds """ seconds: int nanos: int def __str__(self): secs = self.seconds + self.nanos / 1e9 dt = datetime.fromtimestamp(secs, timezone.utc) return dt.strftime('%Y-%m-%dT%H:%M:%S.%f') + "Z" # noinspection PyTypeChecker def _asDict(self): return asdict(self) @classmethod def _fromDict(cls, obj: dict) -> Self: return cls(**obj) @classmethod def from_str(cls, timeStr: str) -> Self: """ Returns a TAITime given a string in ISO format (ex: "2021-09-20T18:44:12.419084072Z"). """ t = parser.isoparse(timeStr).timestamp() seconds = int(t) nanos = int((t - seconds) * 1e9) return cls(seconds, nanos) @classmethod def now(cls) -> Self: """ Returns a TAITime with the current time. """ t = Time.now().tai.value.timestamp() seconds = int(t) nanos = int((t - seconds) * 1e9) return cls(seconds, nanos) @classmethod def after(cls, duration: timedelta) -> Self: """ Returns a UTCTime with the current time plus the given duration. """ t = Time.now().tai.value.timestamp() + duration.total_seconds() seconds = int(t) nanos = int((t - seconds) * 1e9) return cls(seconds, nanos) def value(self) -> datetime: secs = self.seconds + self.nanos / 1e9 return datetime.fromtimestamp(secs, timezone.utc) def currentInstant(self) -> datetime: return Time.now().tai.value def durationFromNow(self) -> timedelta: return self.value() - self.currentInstant() def toUTC(self) -> UTCTime: t = Time.now() diff = t.unix_tai - t.unix return UTCTime(self.seconds - diff, self.nanos)
Creates a TAITime containing seconds since the epoch (1970) and the offset from seconds in nanoseconds
Ancestors
Static methods
def after(duration: datetime.timedelta) ‑> Self
-
Returns a UTCTime with the current time plus the given duration.
def from_str(timeStr: str) ‑> Self
-
Returns a TAITime given a string in ISO format (ex: "2021-09-20T18:44:12.419084072Z").
def now() ‑> Self
-
Returns a TAITime with the current time.
Instance variables
var nanos : int
-
The type of the None singleton.
var seconds : int
-
The type of the None singleton.
Methods
def currentInstant(self) ‑> datetime.datetime
-
Expand source code
def currentInstant(self) -> datetime: return Time.now().tai.value
def durationFromNow(self) ‑> datetime.timedelta
-
Expand source code
def durationFromNow(self) -> timedelta: return self.value() - self.currentInstant()
def toUTC(self) ‑> UTCTime
-
Expand source code
def toUTC(self) -> UTCTime: t = Time.now() diff = t.unix_tai - t.unix return UTCTime(self.seconds - diff, self.nanos)
Inherited members
class TMTTime
-
Expand source code
class TMTTime: """ Represents an instantaneous point in time. Supports 2 timescales: - UTCTime for Coordinated Universal Time (UTC) and - TAITime for International Atomic Time (TAI) """ def value(self) -> datetime: """ the underlying datetime """ pass def durationFromNow(self) -> timedelta: pass def offsetFromNow(self) -> timedelta: return self.durationFromNow() def currentInstant(self) -> datetime: pass
Represents an instantaneous point in time. Supports 2 timescales: - UTCTime for Coordinated Universal Time (UTC) and - TAITime for International Atomic Time (TAI)
Subclasses
Methods
def currentInstant(self) ‑> datetime.datetime
-
Expand source code
def currentInstant(self) -> datetime: pass
def durationFromNow(self) ‑> datetime.timedelta
-
Expand source code
def durationFromNow(self) -> timedelta: pass
def offsetFromNow(self) ‑> datetime.timedelta
-
Expand source code
def offsetFromNow(self) -> timedelta: return self.durationFromNow()
def value(self) ‑> datetime.datetime
-
Expand source code
def value(self) -> datetime: """ the underlying datetime """ pass
the underlying datetime
class TimeConstants
-
Expand source code
class TimeConstants: taiOffset = 37
Class variables
var taiOffset
-
The type of the None singleton.
class UTCTime (seconds: int, nanos: int)
-
Expand source code
@dataclass class UTCTime(TMTTime): """ Creates a UTCTime containing seconds since the epoch (1970) and the offset from seconds in nanoseconds """ seconds: int nanos: int def __str__(self): secs = self.seconds + self.nanos / 1e9 dt = datetime.fromtimestamp(secs, timezone.utc) return dt.strftime('%Y-%m-%dT%H:%M:%S.%f') + "Z" # --- For CBOR format --- # noinspection PyTypeChecker def _asDict(self): return asdict(self) @classmethod def _fromDict(cls, obj: dict) -> Self: return cls(**obj) @classmethod def from_str(cls, timeStr: str) -> Self: """ Returns a UTCTime given a string in ISO format (ex: "2021-09-20T18:44:12.419084072Z"). """ t = parser.isoparse(timeStr).timestamp() seconds = int(t) nanos = int((t - seconds) * 1e9) return cls(seconds, nanos) @classmethod def now(cls) -> Self: """ Returns a UTCTime with the current time. """ t = datetime.now(timezone.utc).timestamp() seconds = int(t) nanos = int((t - seconds) * 1e9) return cls(seconds, nanos) @classmethod def after(cls, duration: timedelta) -> Self: """ Returns a UTCTime with the current time plus the given duration. """ t = datetime.now(timezone.utc).timestamp() + duration.total_seconds() seconds = int(t) nanos = int((t - seconds) * 1e9) return cls(seconds, nanos) def value(self) -> datetime: secs = self.seconds + self.nanos / 1e9 return datetime.fromtimestamp(secs, timezone.utc) def currentInstant(self) -> datetime: return datetime.now(timezone.utc) def durationFromNow(self) -> timedelta: return self.value() - self.currentInstant() def toTAI(self): t = Time.now() diff = t.unix_tai - t.unix return TAITime(self.seconds + diff, self.nanos)
Creates a UTCTime containing seconds since the epoch (1970) and the offset from seconds in nanoseconds
Ancestors
Static methods
def after(duration: datetime.timedelta) ‑> Self
-
Returns a UTCTime with the current time plus the given duration.
def from_str(timeStr: str) ‑> Self
-
Returns a UTCTime given a string in ISO format (ex: "2021-09-20T18:44:12.419084072Z").
def now() ‑> Self
-
Returns a UTCTime with the current time.
Instance variables
var nanos : int
-
The type of the None singleton.
var seconds : int
-
The type of the None singleton.
Methods
def currentInstant(self) ‑> datetime.datetime
-
Expand source code
def currentInstant(self) -> datetime: return datetime.now(timezone.utc)
def durationFromNow(self) ‑> datetime.timedelta
-
Expand source code
def durationFromNow(self) -> timedelta: return self.value() - self.currentInstant()
def toTAI(self)
-
Expand source code
def toTAI(self): t = Time.now() diff = t.unix_tai - t.unix return TAITime(self.seconds + diff, self.nanos)
Inherited members