Skip to content

Instantly share code, notes, and snippets.

@tiagocordeiro
Last active May 11, 2018 23:10
Show Gist options
  • Save tiagocordeiro/7f24be8666af2bd684e6cb364de4d2b6 to your computer and use it in GitHub Desktop.
Save tiagocordeiro/7f24be8666af2bd684e6cb364de4d2b6 to your computer and use it in GitHub Desktop.
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