Last active
August 29, 2015 14:11
-
-
Save dlo/a44885a24a58c22aad4f 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
import datetime | |
class FakeDateTime(datetime.datetime): | |
def __eq__(self, instance): | |
try: | |
return (self.year, self.month, self.day, self.hour, self.minute, self.second) == (instance.year, instance.month, instance.day, instance.hour, instance.minute, instance.second) | |
except: | |
return False | |
@classmethod | |
def today(cls): | |
return cls(2014, 12, 22, 17, 9, 48, 647196) | |
class FakeDate(datetime.date): | |
def __eq__(self, instance): | |
return (self.year, self.month, self.day) == (instance.year, instance.month, instance.day) | |
@classmethod | |
def today(cls): | |
return cls(2014, 12, 22) | |
datetime.date = FakeDate | |
datetime.datetime = FakeDateTime |
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
import datetime | |
class FakeDateType(type): | |
def __instancecheck__(self, instance): | |
return isinstance(instance, datetime.date) | |
class FakeDateTime(datetime.datetime): | |
def __eq__(self, instance): | |
try: | |
return (self.year, self.month, self.day, self.hour, self.minute, self.second) == (instance.year, instance.month, instance.day, instance.hour, instance.minute, instance.second) | |
except: | |
return False | |
@classmethod | |
def today(cls): | |
return cls(2014, 12, 22, 17, 9, 48, 647196) | |
class FakeDate(datetime.date): | |
__metaclass__ = FakeDateType | |
def __eq__(self, instance): | |
return (self.year, self.month, self.day) == (instance.year, instance.month, instance.day) | |
@classmethod | |
def today(cls): | |
return cls(2014, 12, 22) | |
datetime.date = FakeDate | |
datetime.datetime = FakeDateTime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment