Compare commits

...

1 Commits

Author SHA1 Message Date
Timo Furrer fa1c4eb600 Include epoch microseconds in DT comparison methods. Closes #156 2019-08-24 23:22:35 +02:00
+11 -8
View File
@@ -78,7 +78,10 @@ class MayaDT(object):
def __init__(self, epoch): def __init__(self, epoch):
super(MayaDT, self).__init__() 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): def __repr__(self):
return "<MayaDT epoch={}>".format(self._epoch) return "<MayaDT epoch={}>".format(self._epoch)
@@ -92,30 +95,30 @@ class MayaDT(object):
@validate_class_type_arguments("==") @validate_class_type_arguments("==")
def __eq__(self, maya_dt): def __eq__(self, maya_dt):
return int(self._epoch) == int(maya_dt._epoch) return self._epoch == maya_dt._epoch
@validate_class_type_arguments("!=") @validate_class_type_arguments("!=")
def __ne__(self, maya_dt): def __ne__(self, maya_dt):
return int(self._epoch) != int(maya_dt._epoch) return self._epoch != maya_dt._epoch
@validate_class_type_arguments("<") @validate_class_type_arguments("<")
def __lt__(self, maya_dt): def __lt__(self, maya_dt):
return int(self._epoch) < int(maya_dt._epoch) return self._epoch < maya_dt._epoch
@validate_class_type_arguments("<=") @validate_class_type_arguments("<=")
def __le__(self, maya_dt): def __le__(self, maya_dt):
return int(self._epoch) <= int(maya_dt._epoch) return self._epoch <= maya_dt._epoch
@validate_class_type_arguments(">") @validate_class_type_arguments(">")
def __gt__(self, maya_dt): def __gt__(self, maya_dt):
return int(self._epoch) > int(maya_dt._epoch) return self._epoch > maya_dt._epoch
@validate_class_type_arguments(">=") @validate_class_type_arguments(">=")
def __ge__(self, maya_dt): def __ge__(self, maya_dt):
return int(self._epoch) >= int(maya_dt._epoch) return self._epoch >= maya_dt._epoch
def __hash__(self): def __hash__(self):
return hash(int(self.epoch)) return hash(self.epoch)
def __add__(self, duration): def __add__(self, duration):
return self.add(seconds=_seconds_or_timedelta(duration).total_seconds()) return self.add(seconds=_seconds_or_timedelta(duration).total_seconds())