The general convention for a generic range (x,y)
is that x is inclusive and y is exclusive.
For Python datetime.time
type, datetime.time.max
is time(23, 59, 59, 999999)
, so it doesn't seem to allow to use the conventional range check on the upper end. For example, if I want to check a time range between 10 am and midnight, I might want a range like this: (time(10), time(24))
. But time(24)
is not valid, even as a sentinel value.
On the other hand, we can't make x exclusive and y inclusive, because then we lose time(0)
as a value.
Should range checks on time be inclusive? Something about it doesn't seem right to me, but I can't articulate it.
答案 0 :(得分:0)
午夜使用0
代替:
(time(10), time(24))
使用:
# From midnight (0:00) to 10am (10:00)
(time(0), time(10))