@@ -542,12 +542,17 @@ def pendingPomodoros(self) -> Sequence[Pomodoro]:
542
542
allPending .pop (0 )
543
543
return allPending
544
544
545
- def bonusPomodoro (self , currentTime : datetime ) -> Pomodoro :
545
+ def bonusPomodoro (self , currentTime : datetime ) -> None :
546
546
"""
547
547
Create a new pomodoro that doesn't overlap with existing ones.
548
548
"""
549
549
550
550
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
+ """
551
556
allIntervals = self .elapsedIntervals + self .pendingIntervals
552
557
position = slice (len (self .pendingIntervals ), 0 )
553
558
if allIntervals :
@@ -565,41 +570,43 @@ def lengths() -> tuple[slice, datetime, timedelta, timedelta]:
565
570
pomodoroLength = firstPom .endTime - firstPom .startTime
566
571
breakLength = firstBreak .endTime - firstBreak .startTime
567
572
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 )
584
573
else :
585
574
# Variables (we need to save these attributes in the
586
575
# constructor so we don't need to synthesize defaults here.)
587
576
pomodoroLength = timedelta (minutes = 25 )
588
577
breakLength = timedelta (minutes = 5 )
589
578
startingPoint = self .endTime
590
579
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
+
591
597
return position , startingPoint , pomodoroLength , breakLength
592
598
593
599
position , startingPoint , pomodoroLength , breakLength = lengths ()
594
600
newStartTime = max (startingPoint , currentTime )
601
+ if (newStartTime + pomodoroLength ).date () != self .startTime .date ():
602
+ return None
595
603
newPomodoro = Pomodoro (
596
604
None , newStartTime , newStartTime + pomodoroLength
597
605
)
598
606
newBreak = Break (
599
607
newPomodoro .endTime , newPomodoro .endTime + breakLength
600
608
)
601
609
self .pendingIntervals [position ] = [newPomodoro , newBreak ]
602
- return newPomodoro
603
610
604
611
def advanceToTime (
605
612
self , currentTimestamp : float , observer : PomObserver
0 commit comments