Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include epoch microseconds in DT comparison methods. Closes #156 #157

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/maya/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ class MayaDT(object):

def __init__(self, epoch):
super(MayaDT, self).__init__()
self._epoch = epoch
# round the given epoch's microseconds to 6 digits
# to be compatible with Python's datetime.microseconds.
# See: https://docs.python.org/3/library/datetime.html#datetime.datetime.microsecond
self._epoch = round(epoch, 6)

def __repr__(self):
return "<MayaDT epoch={}>".format(self._epoch)
Expand All @@ -92,30 +95,30 @@ def __format__(self, *args, **kwargs):

@validate_class_type_arguments("==")
def __eq__(self, maya_dt):
return int(self._epoch) == int(maya_dt._epoch)
return self._epoch == maya_dt._epoch

@validate_class_type_arguments("!=")
def __ne__(self, maya_dt):
return int(self._epoch) != int(maya_dt._epoch)
return self._epoch != maya_dt._epoch

@validate_class_type_arguments("<")
def __lt__(self, maya_dt):
return int(self._epoch) < int(maya_dt._epoch)
return self._epoch < maya_dt._epoch

@validate_class_type_arguments("<=")
def __le__(self, maya_dt):
return int(self._epoch) <= int(maya_dt._epoch)
return self._epoch <= maya_dt._epoch

@validate_class_type_arguments(">")
def __gt__(self, maya_dt):
return int(self._epoch) > int(maya_dt._epoch)
return self._epoch > maya_dt._epoch

@validate_class_type_arguments(">=")
def __ge__(self, maya_dt):
return int(self._epoch) >= int(maya_dt._epoch)
return self._epoch >= maya_dt._epoch

def __hash__(self):
return hash(int(self.epoch))
return hash(self.epoch)

def __add__(self, duration):
return self.add(seconds=_seconds_or_timedelta(duration).total_seconds())
Expand Down