diff options
Diffstat (limited to 'overlays/worktime')
| -rwxr-xr-x | overlays/worktime/worktime/__main__.py | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index ba6c5ff6..f0363777 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py | |||
| @@ -610,40 +610,50 @@ def time_worked(now, waybar, **args): | |||
| 610 | worked = now.time_worked - then.time_worked | 610 | worked = now.time_worked - then.time_worked |
| 611 | 611 | ||
| 612 | out_text = None | 612 | out_text = None |
| 613 | out_class = "stopped" | 613 | out_class = "running" if now.running_entry else "stopped" |
| 614 | tooltip = tooltip_timedelta(worked) | 614 | tooltip = tooltip_timedelta(worked) |
| 615 | target_time = max(then.time_per_day(then.now.date()), now.time_per_day(now.now.date())) if then.time_per_day(then.now.date()) and now.time_per_day(now.now.date()) else (then.time_per_day(then.now.date()) if then.time_per_day(then.now.date()) else now.time_per_day(now.now.date())); | ||
| 616 | difference = target_time - worked | ||
| 617 | difference_pull_forward = difference + now.time_pulled_forward | ||
| 618 | if now.running_entry and difference_pull_forward < timedelta(seconds=0): | ||
| 619 | out_class = "over" | ||
| 615 | if args['do_round']: | 620 | if args['do_round']: |
| 616 | total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) | 621 | total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) |
| 617 | (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) | 622 | (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) |
| 618 | sign = '' if total_minutes_difference >= 0 else '-' | 623 | sign = '' if total_minutes_difference >= 0 else '-' |
| 619 | |||
| 620 | difference_string = f"{sign}" | ||
| 621 | if hours_difference != 0: | ||
| 622 | difference_string += f"{hours_difference}h" | ||
| 623 | if hours_difference == 0 or minutes_difference != 0: | ||
| 624 | difference_string += f"{minutes_difference}m" | ||
| 625 | |||
| 626 | clockout_time = None | ||
| 627 | clockout_difference = None | ||
| 628 | if then.now_is_workday or now.now_is_workday: | ||
| 629 | target_time = max(then.time_per_day(then.now.date()), now.time_per_day(now.now.date())) if then.time_per_day(then.now.date()) and now.time_per_day(now.now.date()) else (then.time_per_day(then.now.date()) if then.time_per_day(then.now.date()) else now.time_per_day(now.now.date())); | ||
| 630 | difference = target_time - worked | ||
| 631 | clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) | ||
| 632 | clockout_time = now.now + difference | ||
| 633 | exact_clockout_time = clockout_time | ||
| 634 | clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) | ||
| 635 | clockout_time = clockout_time.replace(second = 0, microsecond = 0) | ||
| 636 | 624 | ||
| 637 | if now.running_entry and clockout_time and clockout_difference >= 0: | 625 | difference_string = f"{sign}" |
| 638 | out_class = "running" | 626 | if hours_difference != 0: |
| 639 | out_text = f"{difference_string}/{clockout_time:%H:%M}" | 627 | difference_string += f"{hours_difference}h" |
| 640 | tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M}" | 628 | if hours_difference == 0 or minutes_difference != 0: |
| 641 | else: | 629 | difference_string += f"{minutes_difference}m" |
| 642 | if now.running_entry: | 630 | |
| 643 | out_class = "over" | 631 | def round_clockout_time(difference): |
| 644 | out_text = difference_string | 632 | clockout_time = None |
| 633 | clockout_difference = None | ||
| 634 | if then.now_is_workday or now.now_is_workday: | ||
| 635 | clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) | ||
| 636 | clockout_time = now.now + difference | ||
| 637 | exact_clockout_time = clockout_time | ||
| 638 | clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) | ||
| 639 | clockout_time = clockout_time.replace(second = 0, microsecond = 0) | ||
| 640 | |||
| 641 | return clockout_time, exact_clockout_time, clockout_difference | ||
| 642 | |||
| 643 | clockout_time, exact_clockout_time, clockout_difference = round_clockout_time(difference) | ||
| 644 | clockout_time_pull_forward, exact_clockout_time_pull_forward, clockout_difference_pull_forward = round_clockout_time(difference_pull_forward) | ||
| 645 | if now.running_entry and clockout_time and (clockout_difference >= 0 or clockout_difference_pull_forward >= 0): | ||
| 646 | out_text = f"{difference_string}/{clockout_time:%H:%M}" | ||
| 647 | tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M:%S}" | ||
| 648 | |||
| 649 | if clockout_time_pull_forward != clockout_time: | ||
| 650 | out_text += f"…{clockout_time_pull_forward:%H:%M}" | ||
| 651 | if exact_clockout_time_pull_forward != exact_clockout_time: | ||
| 652 | tooltip += f"…{exact_clockout_time_pull_forward:%H:%M:%S}" | ||
| 653 | else: | ||
| 654 | out_text = difference_string | ||
| 645 | else: | 655 | else: |
| 646 | out_text = str(worked) | 656 | out_text = str(worked) |
| 647 | 657 | ||
| 648 | if waybar: | 658 | if waybar: |
| 649 | json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) | 659 | json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) |
