@@ -582,10 +582,14 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
582
582
# must be validated here to equality check
583
583
if _iterable_not_string (start ):
584
584
start = np .asarray (start )
585
+ if len (start ) == 0 :
586
+ raise ValueError ('number of starting time cannot be 0' )
585
587
else :
586
588
start = np .array ([start ])
587
589
if _iterable_not_string (end ):
588
590
end = np .asarray (end )
591
+ if len (end ) == 0 :
592
+ raise ValueError ('number of ending time cannot be 0' )
589
593
else :
590
594
end = np .array ([end ])
591
595
@@ -595,7 +599,7 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
595
599
596
600
# Validation of input
597
601
if len (start ) != len (end ):
598
- raise ValueError ('number of starting time and ending time'
602
+ raise ValueError ('number of starting time and ending time '
599
603
'must be the same' )
600
604
num_openings = len (start )
601
605
@@ -639,15 +643,17 @@ def _get_daytime_flag(self, start, end):
639
643
640
644
def _next_opening_time (self , other , dir = 1 ):
641
645
"""
642
- If n is positive, return tomorrow's business day opening time.
643
- Otherwise yesterday's business day's opening time.
646
+ If self.n and dir have the same sign, return the earliest opening time
647
+ later than or equal to current time.
648
+ Otherwise the latest opening time earlier than or equal to current time.
644
649
645
650
Opening time always locates on BusinessDay.
646
- Otherwise , closing time may not if business hour extends over midnight.
651
+ However , closing time may not if business hour extends over midnight.
647
652
"""
648
653
earliest_start = self .start [0 ]
649
654
latest_start = self .start [- 1 ]
650
655
if not self .next_bday .onOffset (other ):
656
+ # today is not business day
651
657
other = other + dir * self .next_bday
652
658
if self .n * dir >= 0 :
653
659
return datetime (other .year , other .month , other .day ,
@@ -657,28 +663,34 @@ def _next_opening_time(self, other, dir=1):
657
663
latest_start .hour , latest_start .minute )
658
664
else :
659
665
if self .n * dir >= 0 and latest_start < other .time ():
666
+ # current time is after latest starting time in today
660
667
other = other + dir * self .next_bday
661
668
return datetime (other .year , other .month , other .day ,
662
669
earliest_start .hour , earliest_start .minute )
663
670
elif self .n * dir < 0 and other .time () < earliest_start :
671
+ # current time is before earliest starting time in today
664
672
other = other + dir * self .next_bday
665
673
return datetime (other .year , other .month , other .day ,
666
674
latest_start .hour , latest_start .minute )
667
675
if self .n * dir >= 0 :
676
+ # find earliest starting time later than or equal to current time
668
677
for st in self .start :
669
678
if other .time () <= st :
670
679
return datetime (other .year , other .month , other .day ,
671
680
st .hour , st .minute )
672
681
else :
682
+ # find latest starting time earlier than or equal to current time
673
683
for st in reversed (self .start ):
674
684
if other .time () >= st :
675
685
return datetime (other .year , other .month , other .day ,
676
686
st .hour , st .minute )
677
687
678
688
def _prev_opening_time (self , other ):
679
689
"""
680
- If n is positive, return yesterday's business day opening time.
681
- Otherwise yesterday business day's opening time.
690
+ If n is positive, return the latest opening time earlier than or equal
691
+ to current time.
692
+ Otherwise the earliest opening time later than or equal to current time.
693
+
682
694
"""
683
695
return self ._next_opening_time (other , dir = - 1 )
684
696
0 commit comments