Skip to content

Instantly share code, notes, and snippets.

@ajtack
Created February 7, 2012 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajtack/1758393 to your computer and use it in GitHub Desktop.
Save ajtack/1758393 to your computer and use it in GitHub Desktop.
Time Tolerance Comparator
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