From 7f51888b318f1241946e807f61e16834ece79e06 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 10 Feb 2025 14:26:57 +0100 Subject: ... --- overlays/worktime/worktime/__main__.py | 70 +++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 30 deletions(-) (limited to 'overlays') 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