Skip to content

Commit

Permalink
Make timestamps printable
Browse files Browse the repository at this point in the history
  • Loading branch information
George V. Kouryachy (Fr. Br. George) committed Oct 20, 2023
1 parent 16adcf8 commit 108bb97
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hworker/depot/objects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Interface objects for depot management"""
import datetime
import enum
from collections.abc import Iterator
from inspect import getmembers_static
Expand Down Expand Up @@ -59,9 +60,15 @@ def __getitem__(self, idx: int | str) -> Any:
return getattr(self, name)
raise KeyError(f"Index type must be int ot str, not {idx.__class__}")

def _stringify(self, key, value):
"""Make object field value representaion more human readable"""
if key == "timestamp" and isinstance(value, float):
return str(datetime.datetime.fromtimestamp(value))
return value

def __str__(self):
"""Object representation with only public fields"""
return ", ".join(f"{key}={value}" for key, value in self.items())
return ", ".join(f"{key}={self._stringify(key, value)}" for key, value in self.items())

def __repr__(self):
"""Object representation with ALL fields"""
Expand Down

0 comments on commit 108bb97

Please sign in to comment.