diff options
Diffstat (limited to '')
| -rwxr-xr-x | .config/timewarrior/extensions/total | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/.config/timewarrior/extensions/total b/.config/timewarrior/extensions/total new file mode 100755 index 0000000..8742b68 --- /dev/null +++ b/.config/timewarrior/extensions/total @@ -0,0 +1,38 @@ +#!/bin/env python3 + +from common import loadstdin, dumpstdout, parse_timedelta +from datetime import datetime, timezone, timedelta +from os import getenv +from math import ceil + +RATE = int(getenv('REPORT_RATE', '0')) +BILL = parse_timedelta(getenv('REPORT_BILL', '1:00')) + +def timedelta_ceil(dur: timedelta, diff: timedelta) -> timedelta: + delta = ceil(dur.total_seconds() / diff.total_seconds()) * diff.total_seconds() - dur.total_seconds() + return timedelta(seconds=(dur.total_seconds() + delta)) + + +def main() -> None: + # parse stdin json + meta, data = loadstdin() + + # calc total + total = timedelta(0) + for e in data: + startt = datetime.fromisoformat(e['start']) + endt = datetime.fromisoformat(e['end']) + total += endt - startt + + # calc amount + total_billable = timedelta_ceil(total, BILL) + total_amount = (total_billable.total_seconds() / 3600) * RATE + + # presentation + print(f"total => {total}") + print(f"bill => {total_billable}") + print(f"{total_billable} @ {RATE} EUR => {total_amount} EUR") + + +if __name__ == "__main__": + main() |