From 7f51888b318f1241946e807f61e16834ece79e06 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 10 Feb 2025 14:26:57 +0100 Subject: ... --- flake.lock | 30 +++++++-------- overlays/worktime/worktime/__main__.py | 70 +++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/flake.lock b/flake.lock index 692fac3e..239dbba0 100644 --- a/flake.lock +++ b/flake.lock @@ -397,11 +397,11 @@ "xwayland-satellite-unstable": "xwayland-satellite-unstable" }, "locked": { - "lastModified": 1739042449, - "narHash": "sha256-9zLFUpEebwhjCgtznsI61gTzefI3+fuXATHUOFzJi5w=", + "lastModified": 1739136145, + "narHash": "sha256-KgADxpdWMVevqNaxpJzlocRU+DclrFSyzvUiGFsARcQ=", "owner": "sodiboo", "repo": "niri-flake", - "rev": "98e3666a9dc4143cbf93d957a15d749b5acef046", + "rev": "c5a3826e2bf96f3092b79415e17703a7b194e1a8", "type": "github" }, "original": { @@ -431,11 +431,11 @@ "niri-unstable": { "flake": false, "locked": { - "lastModified": 1739017614, - "narHash": "sha256-eNiFJzN6o3NYjB5LWtOzrwLFNtl/NshIryWT6dg+6fg=", + "lastModified": 1739187348, + "narHash": "sha256-6upEicgdJH3JaS1oXS+wsgLToU14XL8/aOyL2KcS3KY=", "owner": "yalter", "repo": "niri", - "rev": "8f9a9d4878bc0deaabc1878d9670e91945c63042", + "rev": "c4739895f8d07c13c65361bd2105e186e8d44568", "type": "github" }, "original": { @@ -472,11 +472,11 @@ ] }, "locked": { - "lastModified": 1738466368, - "narHash": "sha256-PZhUjtvQZOH3PO0EYdTpQvcqkgkq1NkP2A6w9SPHYsk=", + "lastModified": 1739071773, + "narHash": "sha256-/Ak+Quinhmdxa9m3shjm4lwwwqmzG8zzGhhhhgR1k9I=", "owner": "Mic92", "repo": "nix-index-database", - "rev": "46a8f5fc9552b776bfc5c5c96ea3bede33f68f52", + "rev": "895d81b6228bbd50a6ef22f5a58a504ca99763ea", "type": "github" }, "original": { @@ -493,11 +493,11 @@ ] }, "locked": { - "lastModified": 1736736253, - "narHash": "sha256-GrktftEfXmmdKOU0yz3QXckDz1ncZ+f4KLU8XnYKYuA=", + "lastModified": 1739078428, + "narHash": "sha256-9Q8lxL99vaTtK/myj+I6vQvzt3uJiCpazq0jovQswGs=", "owner": "AshleyYakeley", "repo": "NixVirt", - "rev": "9063243af5e6674359a0ff7cec57f02eeacf0cea", + "rev": "f2e4e9ad0b02bbd80c509b63d27a2f11359c16a8", "type": "github" }, "original": { @@ -630,11 +630,11 @@ }, "nixpkgs-stable_2": { "locked": { - "lastModified": 1738843498, - "narHash": "sha256-7x+Q4xgFj9UxZZO9aUDCR8h4vyYut4zPUvfj3i+jBHE=", + "lastModified": 1739055578, + "narHash": "sha256-2MhC2Bgd06uI1A0vkdNUyDYsMD0SLNGKtD8600mZ69A=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f5a32fa27df91dfc4b762671a0e0a859a8a0058f", + "rev": "a45fa362d887f4d4a7157d95c28ca9ce2899b70e", "type": "github" }, "original": { 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): worked = now.time_worked - then.time_worked out_text = None - out_class = "stopped" + out_class = "running" if now.running_entry else "stopped" tooltip = tooltip_timedelta(worked) + 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())); + difference = target_time - worked + difference_pull_forward = difference + now.time_pulled_forward + if now.running_entry and difference_pull_forward < timedelta(seconds=0): + out_class = "over" if args['do_round']: - total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) - (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) - sign = '' if total_minutes_difference >= 0 else '-' - - difference_string = f"{sign}" - if hours_difference != 0: - difference_string += f"{hours_difference}h" - if hours_difference == 0 or minutes_difference != 0: - difference_string += f"{minutes_difference}m" - - clockout_time = None - clockout_difference = None - if then.now_is_workday or now.now_is_workday: - 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())); - difference = target_time - worked - clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) - clockout_time = now.now + difference - exact_clockout_time = clockout_time - clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) - clockout_time = clockout_time.replace(second = 0, microsecond = 0) + total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) + (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) + sign = '' if total_minutes_difference >= 0 else '-' - if now.running_entry and clockout_time and clockout_difference >= 0: - out_class = "running" - out_text = f"{difference_string}/{clockout_time:%H:%M}" - tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M}" - else: - if now.running_entry: - out_class = "over" - out_text = difference_string + difference_string = f"{sign}" + if hours_difference != 0: + difference_string += f"{hours_difference}h" + if hours_difference == 0 or minutes_difference != 0: + difference_string += f"{minutes_difference}m" + + def round_clockout_time(difference): + clockout_time = None + clockout_difference = None + if then.now_is_workday or now.now_is_workday: + clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) + clockout_time = now.now + difference + exact_clockout_time = clockout_time + clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) + clockout_time = clockout_time.replace(second = 0, microsecond = 0) + + return clockout_time, exact_clockout_time, clockout_difference + + clockout_time, exact_clockout_time, clockout_difference = round_clockout_time(difference) + clockout_time_pull_forward, exact_clockout_time_pull_forward, clockout_difference_pull_forward = round_clockout_time(difference_pull_forward) + if now.running_entry and clockout_time and (clockout_difference >= 0 or clockout_difference_pull_forward >= 0): + out_text = f"{difference_string}/{clockout_time:%H:%M}" + tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M:%S}" + + if clockout_time_pull_forward != clockout_time: + out_text += f"…{clockout_time_pull_forward:%H:%M}" + if exact_clockout_time_pull_forward != exact_clockout_time: + tooltip += f"…{exact_clockout_time_pull_forward:%H:%M:%S}" + else: + out_text = difference_string else: - out_text = str(worked) + out_text = str(worked) if waybar: json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) -- cgit v1.2.3