Skip to content

Commit

Permalink
some corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Jul 27, 2022
1 parent 2cc4f52 commit f05b3b4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions spacepackets/ccsds/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def pack(self) -> bytearray:
pass

@abstractmethod
def as_unix_seconds(self) -> int:
def as_unix_seconds(self) -> float:
pass

@abstractmethod
Expand Down Expand Up @@ -100,15 +100,20 @@ def _calculate_unix_seconds(self):
unix_days = convert_ccsds_days_to_unix_days(self._ccsds_days)
self._unix_seconds = unix_days * (24 * 60 * 60)
seconds_of_day = self._ms_of_day / 1000.0
self._unix_seconds += seconds_of_day
if self._unix_seconds < 0:
self._unix_seconds -= seconds_of_day
else:
self._unix_seconds += seconds_of_day

def _calculate_date_time(self):
if self._unix_seconds < 0:
self._date_time = datetime.datetime(1970, 1, 1) + datetime.timedelta(
seconds=self._unix_seconds
)
else:
self._date_time = datetime.datetime.utcfromtimestamp(self._unix_seconds)
self._date_time = datetime.datetime.utcfromtimestamp(
self._unix_seconds
)

@property
def pfield(self) -> bytes:
Expand Down Expand Up @@ -177,9 +182,8 @@ def ms_of_day(seconds_since_epoch: Optional[float] = None):
math.floor((seconds_since_epoch % SECONDS_PER_DAY) * 1000 + fraction_ms)
)

def as_unix_seconds(self) -> int:
def as_unix_seconds(self) -> float:
return self._unix_seconds

@abstractmethod
def as_datetime(self) -> datetime:
return self._date_time

0 comments on commit f05b3b4

Please sign in to comment.