Last active
May 11, 2018 23:10
-
-
Save tiagocordeiro/7f24be8666af2bd684e6cb364de4d2b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import datetime | |
def time_in_range(start, end, x): | |
"""Return true if x is in the range [start, end]""" | |
if start <= end: | |
return start <= x <= end | |
else: | |
return start <= x or x <= end | |
if __name__ == '__main__': | |
start = datetime.time(23, 0, 0) | |
end = datetime.time(1, 0, 0) | |
time_in_range(start, end, datetime.time(23, 30, 0)) | |
time_in_range(start, end, datetime.time(12, 30, 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment