Created
November 30, 2016 15:56
-
-
Save jholloway7/c5f851d60bdc51b2b9812dfe1d29bb38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
def is_between(dttm, begin, end): | |
begin_check = datetime.combine(dttm.date(), begin) | |
end_check = datetime.combine(dttm.date(), end) | |
# Handle the case where the range crosses midnight (or both times given are | |
# the same, assuming semantically you want this mean a 24-hr range instead | |
# of a null range that always returns False) | |
if end <= begin: | |
end_check += timedelta(days=1) | |
return begin_check <= dttm <= end_check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment