Skip to content

Commit 7001cd6

Browse files
committed
fix old-school bonus pomodoros to not overlap and to not bleed into the next day
This commit was sponsored by Derek Veit, Jason Walker, Jason Mills, and my other patrons. If you want to join them, you can support my work at https://glyph.im/patrons/.
1 parent 6af247c commit 7001cd6

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/pomodouroboros/pommodel.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,17 @@ def pendingPomodoros(self) -> Sequence[Pomodoro]:
542542
allPending.pop(0)
543543
return allPending
544544

545-
def bonusPomodoro(self, currentTime: datetime) -> Pomodoro:
545+
def bonusPomodoro(self, currentTime: datetime) -> None:
546546
"""
547547
Create a new pomodoro that doesn't overlap with existing ones.
548548
"""
549549

550550
def lengths() -> tuple[slice, datetime, timedelta, timedelta]:
551+
"""
552+
Look for the place to insert the new pomodoro, expressed as the
553+
position to insert it in the pending intervals list (a 0-width
554+
slice) and the start time, pomodoro length, and break length.
555+
"""
551556
allIntervals = self.elapsedIntervals + self.pendingIntervals
552557
position = slice(len(self.pendingIntervals), 0)
553558
if allIntervals:
@@ -565,41 +570,43 @@ def lengths() -> tuple[slice, datetime, timedelta, timedelta]:
565570
pomodoroLength = firstPom.endTime - firstPom.startTime
566571
breakLength = firstBreak.endTime - firstBreak.startTime
567572
startingPoint = currentTime
568-
569-
for idx, anInterval in enumerate(allIntervals):
570-
position = slice(idx, 0)
571-
if anInterval.startTime > startingPoint:
572-
potentialEnd = (
573-
startingPoint + pomodoroLength + breakLength
574-
)
575-
if (
576-
not anInterval.startTime
577-
< potentialEnd
578-
< anInterval.endTime
579-
):
580-
break
581-
startingPoint = anInterval.endTime
582-
else:
583-
position = slice(len(self.pendingIntervals), 0)
584573
else:
585574
# Variables (we need to save these attributes in the
586575
# constructor so we don't need to synthesize defaults here.)
587576
pomodoroLength = timedelta(minutes=25)
588577
breakLength = timedelta(minutes=5)
589578
startingPoint = self.endTime
590579

580+
581+
for idx, anInterval in enumerate(self.pendingIntervals):
582+
position = slice(idx, 0)
583+
if anInterval.startTime > startingPoint:
584+
potentialEnd = (
585+
startingPoint + pomodoroLength + breakLength
586+
)
587+
if (
588+
not anInterval.startTime
589+
< potentialEnd
590+
< anInterval.endTime
591+
):
592+
break
593+
startingPoint = anInterval.endTime
594+
else:
595+
position = slice(len(self.pendingIntervals), 0)
596+
591597
return position, startingPoint, pomodoroLength, breakLength
592598

593599
position, startingPoint, pomodoroLength, breakLength = lengths()
594600
newStartTime = max(startingPoint, currentTime)
601+
if (newStartTime + pomodoroLength).date() != self.startTime.date():
602+
return None
595603
newPomodoro = Pomodoro(
596604
None, newStartTime, newStartTime + pomodoroLength
597605
)
598606
newBreak = Break(
599607
newPomodoro.endTime, newPomodoro.endTime + breakLength
600608
)
601609
self.pendingIntervals[position] = [newPomodoro, newBreak]
602-
return newPomodoro
603610

604611
def advanceToTime(
605612
self, currentTimestamp: float, observer: PomObserver

0 commit comments

Comments
 (0)