removing seconds from timestamp; wider column for name when printing ls/ ps

This commit is contained in:
2024-06-13 11:59:46 +02:00
parent c78b314684
commit 5d8f119495
3 changed files with 33 additions and 10 deletions

View File

@@ -24,7 +24,8 @@ class TimeSlot():
@start.setter
def start(self, d: datetime):
self._start = d.timestamp()
_d = d.replace(second=0, microsecond=0)
self._start = _d.timestamp()
@property
def end(self):
@@ -34,9 +35,10 @@ class TimeSlot():
@end.setter
def end(self, d: datetime):
if d < self.start:
_d = d.replace(second=0, microsecond=0)
if _d < self.start:
raise ValueError("End date must be after the start date.")
self._end = d.timestamp()
self._end = _d.timestamp()
def end_now(self):
self.end = datetime.now()

View File

@@ -2,14 +2,14 @@ from .TimeSlot import TimeSlot
def convert_to_table(time_slot_list: list[TimeSlot]):
widths = [20, 26, 26]
widths = [30, 26, 26]
r_str = f"+{'-'*(widths[0]+2)}+{'-'*(widths[1]+2)}+{'-'*(widths[2]+2)}+\n"
r_str += f"| {'Name':<20} | {'Startzeitpunkt':<26} | {'Endzeitpunkt':<26} |\n"
r_str += f"| {'Name':<30} | {'Startzeitpunkt':<26} | {'Endzeitpunkt':<26} |\n"
r_str += f"+{'-'*(widths[0]+2)}+{'-'*(widths[1]+2)}+{'-'*(widths[2]+2)}+\n"
for time_slot in time_slot_list:
r_str += f"| {time_slot.name:<20} | {str(time_slot.start):<26} | {str(time_slot.end):<26} |\n"
r_str += f"| {time_slot.name:<30} | {str(time_slot.start):<26} | {str(time_slot.end):<26} |\n"
r_str += f"+{'-'*(widths[0]+2)}+{'-'*(widths[1]+2)}+{'-'*(widths[2]+2)}+"