1
0

Improved time formatting

This commit is contained in:
Jon Michael Aanes 2024-06-08 14:49:26 +02:00
parent c2e90943e9
commit 173de2c252
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -70,8 +70,14 @@ DEFAULT_EST_TIME = datetime.timedelta(hours=1)
ZERO_DURATION = datetime.timedelta(seconds=0)
HOUR = datetime.timedelta(hours=1)
MINUTE = datetime.timedelta(minutes=1)
def fmt_line(label_type: str, label: str, total_time: datetime.timedelta) -> str:
hours = int(total_time / HOUR)
minutes = int((total_time - hours*HOUR)/MINUTE)
return f' {label_type:8} {label:40} {hours:-4d}h {minutes:-2d}m\n'
def generate_report(samples: list[WorkSample]) -> Iterator[str]:
SAMPLE_FILTER = {}
LABEL_FILTER = {}
@ -112,18 +118,13 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]:
label_type = '' # TODO
yield f' {label_type:8} {label:40} {total_time / HOUR:-4.2f} hours\n'
yield fmt_line(label_type, label, total_time)
del label, total_time
yield '-' * 66
yield '\n'
yield ' {label_type:8} {label:40} {hours:-4.0f} hours\n'.format(
label_type='',
label='TOTAL',
hours=time_per_label.get(HIDDEN_LABEL_TOTAL, ZERO_DURATION) / HOUR,
)
yield fmt_line('', 'TOTAL', time_per_label.get(HIDDEN_LABEL_TOTAL, ZERO_DURATION))
def main():
logging.basicConfig()