@@ -583,13 +583,13 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
583
583
if _iterable_not_string (start ):
584
584
start = np .asarray (start )
585
585
if len (start ) == 0 :
586
- raise ValueError ('number of starting time cannot be 0 ' )
586
+ raise ValueError ('Must include at least 1 start time ' )
587
587
else :
588
588
start = np .array ([start ])
589
589
if _iterable_not_string (end ):
590
590
end = np .asarray (end )
591
591
if len (end ) == 0 :
592
- raise ValueError ('number of ending time cannot be 0 ' )
592
+ raise ValueError ('Must include at least 1 end time ' )
593
593
else :
594
594
end = np .array ([end ])
595
595
@@ -614,7 +614,9 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
614
614
total_secs += self ._get_business_hours_by_sec (
615
615
end [i ], start [(i + 1 ) % num_openings ])
616
616
if total_secs != 24 * 60 * 60 :
617
- raise ValueError ('invalid starting and ending time(s)' )
617
+ raise ValueError ('invalid starting and ending time(s): '
618
+ 'opening hours should not touch or overlap with '
619
+ 'one another' )
618
620
619
621
object .__setattr__ (self , "start" , start )
620
622
object .__setattr__ (self , "end" , end )
@@ -641,11 +643,12 @@ def next_bday(self):
641
643
def _get_daytime_flag (self , start , end ):
642
644
return start < end
643
645
644
- def _next_opening_time (self , other , dir = 1 ):
646
+ def _next_opening_time (self , other , sign = 1 ):
645
647
"""
646
- If self.n and dir have the same sign, return the earliest opening time
648
+ If self.n and sign have the same sign, return the earliest opening time
647
649
later than or equal to current time.
648
- Otherwise the latest opening time earlier than or equal to current time.
650
+ Otherwise the latest opening time earlier than or equal to current
651
+ time.
649
652
650
653
Opening time always locates on BusinessDay.
651
654
However, closing time may not if business hour extends over midnight.
@@ -654,25 +657,25 @@ def _next_opening_time(self, other, dir=1):
654
657
latest_start = self .start [- 1 ]
655
658
if not self .next_bday .onOffset (other ):
656
659
# today is not business day
657
- other = other + dir * self .next_bday
658
- if self .n * dir >= 0 :
660
+ other = other + sign * self .next_bday
661
+ if self .n * sign >= 0 :
659
662
return datetime (other .year , other .month , other .day ,
660
663
earliest_start .hour , earliest_start .minute )
661
664
else :
662
665
return datetime (other .year , other .month , other .day ,
663
666
latest_start .hour , latest_start .minute )
664
667
else :
665
- if self .n * dir >= 0 and latest_start < other .time ():
668
+ if self .n * sign >= 0 and latest_start < other .time ():
666
669
# current time is after latest starting time in today
667
- other = other + dir * self .next_bday
670
+ other = other + sign * self .next_bday
668
671
return datetime (other .year , other .month , other .day ,
669
672
earliest_start .hour , earliest_start .minute )
670
- elif self .n * dir < 0 and other .time () < earliest_start :
673
+ elif self .n * sign < 0 and other .time () < earliest_start :
671
674
# current time is before earliest starting time in today
672
- other = other + dir * self .next_bday
675
+ other = other + sign * self .next_bday
673
676
return datetime (other .year , other .month , other .day ,
674
677
latest_start .hour , latest_start .minute )
675
- if self .n * dir >= 0 :
678
+ if self .n * sign >= 0 :
676
679
# find earliest starting time later than or equal to current time
677
680
for st in self .start :
678
681
if other .time () <= st :
@@ -689,10 +692,11 @@ def _prev_opening_time(self, other):
689
692
"""
690
693
If n is positive, return the latest opening time earlier than or equal
691
694
to current time.
692
- Otherwise the earliest opening time later than or equal to current time.
695
+ Otherwise the earliest opening time later than or equal to current
696
+ time.
693
697
694
698
"""
695
- return self ._next_opening_time (other , dir = - 1 )
699
+ return self ._next_opening_time (other , sign = - 1 )
696
700
697
701
def _get_business_hours_by_sec (self , start , end ):
698
702
"""
0 commit comments