def __sub__(self, delta_or_jdt): if isinstance(delta_or_jdt, _std_dt_mod.timedelta): delta = delta_or_jdt njtm = self.__jtm.copy() njtm.tm_sec -= delta.seconds njtm.tm_mday -= delta.days ms = normalize_jtm(njtm, self.microsecond - delta.microseconds) return datetime_from_jtm(njtm, ms, self.tzinfo) if isinstance(delta_or_jdt, _std_dt_mod.datetime): raise TypeError("It doesn't make sense subtract Gregorian date " "from Jalali date") if isinstance(delta_or_jdt, datetime): jdt = delta_or_jdt if (self.tzinfo is None) != (jdt.tzinfo is None): raise TypeError("can't subtract offset-naive and offset-aware" "datetimes") if self.tzinfo != jdt.tzinfo: return (self.replace(tzinfo=None) - self.utcoffset()) - \ (jdt.replace(tzinfo=None) - jdt.utcoffset()) self.__date._compute_yday_wday_if_necessary() onjtm = jdt.jtm.copy() jalali_create_days_from_date(onjtm) dx = _std_dt_mod.timedelta(days=self.__jtm.tm_yday - onjtm.tm_yday, hours=self.hour - jdt.hour, minutes=self.minute - jdt.minute, seconds=self.second - jdt.second, microseconds=(self.microsecond - jdt.microsecond)) return dx raise TypeError( 'Unsupported operand type for -: %s and %s' % (self.__class__.__name__, delta_or_jdt.__class__.__name__))
def __sub__(self, delta_or_jdt): if isinstance(delta_or_jdt, _std_dt_mod.timedelta): delta = delta_or_jdt njtm = self.__jtm.copy() njtm.tm_sec -= delta.seconds njtm.tm_mday -= delta.days ms = normalize_jtm(njtm, self.microsecond - delta.microseconds) return datetime_from_jtm(njtm, ms, self.tzinfo) if isinstance(delta_or_jdt, _std_dt_mod.datetime): raise TypeError("It doesn't make sense subtract Gregorian date " "from Jalali date") if isinstance(delta_or_jdt, datetime): jdt = delta_or_jdt if (self.tzinfo is None) != (jdt.tzinfo is None): raise TypeError("can't subtract offset-naive and offset-aware" "datetimes") if self.tzinfo != jdt.tzinfo: return (self.replace(tzinfo=None) - self.utcoffset()) - \ (jdt.replace(tzinfo=None) - jdt.utcoffset()) self.__date._compute_yday_wday_if_necessary() onjtm = jdt.jtm.copy() jalali_create_days_from_date(onjtm) dx = _std_dt_mod.timedelta(days=self.__jtm.tm_yday-onjtm.tm_yday, hours=self.hour - jdt.hour, minutes=self.minute - jdt.minute, seconds=self.second - jdt.second, microseconds=(self.microsecond - jdt.microsecond)) return dx raise TypeError('Unsupported operand type for -: %s and %s' % (self.__class__.__name__, delta_or_jdt.__class__.__name__))
def __sub__(self, delta_or_date): if isinstance(delta_or_date, _std_dt_mod.timedelta): delta = delta_or_date njtm = self.__jtm.copy() njtm.tm_mday -= delta.days normalize_jtm(njtm) return date(njtm.tm_year, njtm.tm_mon + 1, njtm.tm_mday) if isinstance(delta_or_date, date): jd = delta_or_date onjtm = jd.jtm.copy() self._compute_yday_wday_if_necessary() jalali_create_days_from_date(onjtm) dx = self.__jtm.tm_yday - onjtm.tm_yday return _std_dt_mod.timedelta(days=dx) raise TypeError( 'Unsupported operand type for -: %s and %s' % (self.__class__.__name__, delta_or_date.__class__.__name__))
def __sub__(self, delta_or_date): if isinstance(delta_or_date, _std_dt_mod.timedelta): delta = delta_or_date njtm = self.__jtm.copy() njtm.tm_mday -= delta.days normalize_jtm(njtm) return date(njtm.tm_year, njtm.tm_mon + 1, njtm.tm_mday) if isinstance(delta_or_date, date): jd = delta_or_date onjtm = jd.jtm.copy() self._compute_yday_wday_if_necessary() jalali_create_days_from_date(onjtm) dx = self.__jtm.tm_yday - onjtm.tm_yday return _std_dt_mod.timedelta(days=dx) raise TypeError('Unsupported operand type for -: %s and %s' % (self.__class__.__name__, delta_or_date.__class__.__name__))