Example #1
0
 def __add__(self, delta):
     if isinstance(delta, _std_dt_mod.timedelta):
         njtm = self.__jtm.copy()
         njtm.tm_mday += delta.days
         normalize_jtm(njtm)
         return date(njtm.tm_year, njtm.tm_mon + 1, njtm.tm_mday)
     raise TypeError('Unsupported operand type for +: %s and %s' %
                     (self.__class__.__name__, delta.__class__.__name__))
Example #2
0
 def __add__(self, delta):
     if isinstance(delta, _std_dt_mod.timedelta):
         njtm = self.__jtm.copy()
         njtm.tm_mday += delta.days
         normalize_jtm(njtm)
         return date(njtm.tm_year, njtm.tm_mon + 1, njtm.tm_mday)
     raise TypeError('Unsupported operand type for +: %s and %s' %
                     (self.__class__.__name__, delta.__class__.__name__))
Example #3
0
 def __localtime_offset_decreased_jtm(self):
     # workaround for strftime GMT offset dependecy
     njtm = self.__jtm.copy()
     if self.tzinfo is None:
         njtm.tm_gmtoff = 0
         njtm.tm_sec -= jlocaltime(int(_timestamp())).tm_gmtoff
         njtm.tm_zone = ''
         normalize_jtm(njtm)
     return njtm
Example #4
0
 def __localtime_offset_decreased_jtm(self):
     # workaround for strftime GMT offset dependecy
     njtm = self.__jtm.copy()
     if self.tzinfo is None:
         njtm.tm_gmtoff = 0
         njtm.tm_sec -= jlocaltime(int(_timestamp())).tm_gmtoff
         njtm.tm_zone = ''
         normalize_jtm(njtm)
     return njtm
Example #5
0
 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__))
Example #6
0
 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__))
Example #7
0
 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__))
Example #8
0
 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__))
Example #9
0
 def __add__(self, delta):
     if isinstance(delta, _std_dt_mod.timedelta):
         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)
     raise TypeError('Unsupported operand type for +: %s and %s' %
                     (self.__class__.__name__, delta.__class__.__name__))
Example #10
0
 def __add__(self, delta):
     if isinstance(delta, _std_dt_mod.timedelta):
         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)
     raise TypeError('Unsupported operand type for +: %s and %s' %
                     (self.__class__.__name__, delta.__class__.__name__))