Should time range checks be inclusive or exclusive?

241 views Asked by At

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.

1

There are 1 answers

0
Bluebot On

Use 0 for midnight

Instead of:

(time(10), time(24))

Use:

# From midnight (0:00) to 10am (10:00)
(time(0), time(10))