Created
February 7, 2012 08:57
-
-
Save ajtack/1758393 to your computer and use it in GitHub Desktop.
Time Tolerance Comparator
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
class WithinToleranceOfNow: | |
def __init__(self, expectation = datetime.utcnow()): | |
self.expected_time = expectation | |
def __eq__(self, other): | |
try: | |
parsed_time = datetime.utcfromtimestamp(int(other)) | |
difference = abs(parsed_time - self.expected_time) | |
return (difference.seconds < 10) | |
except AttributeError as e: | |
case.tracker.error("Couldn't compare '" + other + \ | |
"' to expected time " + self.expected_time.strftime("%H:%M")) | |
return False | |
def __repr__(self): | |
# Repr is used when printing lists, and should be a valid Python expression. | |
# I don't know, man. Seems like work. | |
return self.expected_time.strftime("WithinToleranceOfNow(" + self.expected_time.__repr__() + ")") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment