Skip to content

Commit

Permalink
Estimated end time did not consider timeoff. (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
frangiz committed May 12, 2024
1 parent e27ea10 commit 1fcfa6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
17 changes: 13 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,13 @@ def handle_command(cmd: str) -> None:


def _print_estimated_endtime_for_today(
work_blocks: List[WorkBlock], lunch: int = 30
work_blocks: List[WorkBlock], lunch: int = 30, timeoff: int = 0
) -> None:
mins_left_to_work = (
(cfg.workhours_one_day * 60) + lunch - sum(wt.worked_time for wt in work_blocks)
(cfg.workhours_one_day * 60)
+ lunch
- timeoff
- sum(wt.worked_time for wt in work_blocks)
)
if not work_blocks[-1].start:
return
Expand Down Expand Up @@ -245,9 +248,15 @@ def start(start_time: datetime) -> None:
print(f"Starting at {start_time}")
save_timesheet(ts)
if ts.today.lunch > 0:
_print_estimated_endtime_for_today(ts.today.work_blocks, ts.today.lunch)
_print_estimated_endtime_for_today(
work_blocks=ts.today.work_blocks,
lunch=ts.today.lunch,
timeoff=ts.today.time_off_minutes,
)
else:
_print_estimated_endtime_for_today(ts.today.work_blocks)
_print_estimated_endtime_for_today(
work_blocks=ts.today.work_blocks, timeoff=ts.today.time_off_minutes
)


def stop(stop_time: datetime, comment: Optional[str] = None) -> None:
Expand Down
7 changes: 6 additions & 1 deletion test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,21 @@ def test_summary_month(capsys) -> None:
assert_captured_out_starts_with(expected, captured)


def test_timeoff_half_day() -> None:
def test_timeoff_half_day(capsys) -> None:
main.cfg.datafile = "2021-04-timesheet.json"
with freeze_time("2021-04-02"): # A Friday
handle_command("timeoff 4")
handle_command("start 08:00")
captured = capsys.readouterr()
write_captured_output(captured.out)
handle_command("stop 12:02")

ts = load_timesheet()
assert ts.today.time_off_minutes == 4 * 60
assert ts.today.flex_minutes == 2
assert (
"Estimated end time for today with 30 min lunch is 12:30:00" in captured.out
)


def test_timeoff_full_day() -> None:
Expand Down

0 comments on commit 1fcfa6b

Please sign in to comment.