Example #1
0
    def __add__(self, other):
        result = datetime.__add__(self, other)

        if result is NotImplemented:
            return result

        return self.from_datetime(result)
Example #2
0
    def __add__(self, other):
        # __add__ is only supported between datetime and timedelta
        dt = datetime.__add__(self.replace(tzinfo=None), other)

        # Required to support the case where tzinfo is None
        dt = dt.replace(tzinfo=self.tzinfo)
        return self.__class__.from_datetime(dt)
Example #3
0
 def __add__(self, arg):
     if isinstance(arg, int) or isinstance(arg, long) or isinstance(
             arg, float):
         offset = arg
     key = {"seconds": offset}
     dt = datetime.__add__(self, timedelta(**key))
     return self._fromDateTime(dt)
Example #4
0
    def __add__(self, addend):
        """Autonormalized addition of datetimes and timedeltas."""

        added = _datetime.__add__(self, addend)
        if added is NotImplemented:
            return added
        added = self.tzinfo.normalize(added)
        return datetime.__from_datetime_with_tz(added)
Example #5
0
 def __add__(self, x):
     """
     Aggiunge 'x' alla data; se x è di tipo numerico (int/float/long) viene
     restituita la data maggiorata di 'x' giorni, altrimenti funzionalità
     standard della somma di un datetime.datetime con altro (timdelta)
     """
     if isinstance(x, (int, float, long)):
         return _datetime(self.year, self.month, self.day, self.hour, self.minute, self.second)+timedelta(days=x)
     d = dtime.__add__(self, x)
     return _datetime(d.year, d.month, d.day, d.hour, d.minute, d.second)
Example #6
0
 def __add__(self, x):
     """
     Aggiunge 'x' alla data; se x è di tipo numerico (int/float/long) viene
     restituita la data maggiorata di 'x' giorni, altrimenti funzionalità
     standard della somma di un datetime.datetime con altro (timdelta)
     """
     if isinstance(x, (int, float, long)):
         return _datetime(self.year, self.month, self.day, self.hour,
                          self.minute, self.second) + timedelta(days=x)
     d = dtime.__add__(self, x)
     return _datetime(d.year, d.month, d.day, d.hour, d.minute, d.second)
Example #7
0
 def __add__(self,t):
     # if return value is <type 'timedelta'>
     if t.__class__ == self.__class__ or \
        t.__class__ == self.__ZERODATE[0].__class__:
         return datetime.__add__(self,t)
     # else (mydatetime-timedelta) should be mydatetime
     else:
         tmp = super(mydatetime,self).__add__(self,t)
         return self.__class__(
             tmp.year,tmp.month,tmp.day,tmp.hour,
             tmp.minute,tmp.second,tmp.microsecond,tmp.tzinfo
             )
Example #8
0
 def __add__(self, t):
     d = self
     if getattr(t, "years", 0) \
     or getattr(t, "months", 0):
         # January 31 + 1 month = February 28.
         y = (d.month + t.months - 1) // 12 + d.year + t.years
         m = (d.month + t.months + 0) % 12 or 12
         r = monthrange(y, m)
         d = date(y, m, min(d.day, r[1]), d.hour, d.minute, d.second,
                  d.microsecond)
     d = datetime.__add__(d, t)
     return date(d.year, d.month, d.day, d.hour, d.minute, d.second,
                 d.microsecond, self.format)
Example #9
0
    def __add__(self, other):
        if isinstance(other, TimeDelta) or isinstance(other, timedelta):
            # add values without sub-seconds, then deal with normalized
            # sub-seconds separately.
            # FIXME: this results in 2 ctor calls, make more efficient
            whole_seconds_self = self.todatetime().replace(microsecond=0)
            whole_seconds_other = timedelta(seconds=int(other.total_seconds()))

            result = datetime.__add__(whole_seconds_self, whole_seconds_other)

            (
                frac_second_self,
                frac_second_other,
                result_frac_second_exponent,
            ) = util.normalize_frac_seconds(self, other)

            result_frac_second = frac_second_self + frac_second_other
            result_frac_second_multiplied = result_frac_second * (
                10**result_frac_second_exponent)
            if result_frac_second_multiplied >= 1:
                result += timedelta(seconds=1)
                result_frac_second -= 10**abs(result_frac_second_exponent)
            elif result_frac_second_multiplied < 0:
                result -= timedelta(seconds=1)
                result_frac_second = (
                    10**abs(result_frac_second_exponent)) + result_frac_second

            # FIXME: fold?
            return DateTime(
                year=result.year,
                month=result.month,
                day=result.day,
                hour=result.hour,
                minute=result.minute,
                second=result.second,
                tzinfo=result.tzinfo,
                frac_second=result_frac_second,
                frac_second_exponent=result_frac_second_exponent,
            )

        return NotImplemented
Example #10
0
 def __add__(self, other):
     return datetimedict.fromdatetime(datetime.__add__(self, other))
Example #11
0
 def __add__(self, other):
     return datetimedict.fromdatetime(datetime.__add__(self, other))
Example #12
0
 def _add_and_convert(a, b):
     return T(datetime.__add__(a, b))
Example #13
0
 def __add__(self, time):
     d = datetime.__add__(self, time)
     return date(d.year, d.month, d.day, d.hour, d.minute, d.second,
                 d.microsecond, self.format)
Example #14
0
    def __add__(self, addend):
        """Autonormalized addition of datetimes and timedeltas."""

        added = _datetime.__add__(self, addend)
        added = self.tzinfo.normalize(added)
        return datetime.__from_datetime_with_tz(added)
Example #15
0
 def __add__(a, b):
     return T(datetime.__add__(a, b))
Example #16
0
 def __add__(self, other):
     """Add timedelta to gpsdatetime."""
     crn = datetime.__add__(self.replace(tzinfo=None), other)
     return self.copydt(crn, self.tzinfo)
Example #17
0
 def __add__(self, td):
     newdt = datetime.__add__(self, td)
     return ApexDatetime.from_iso(newdt.isoformat())
Example #18
0
 def __add__(self, time):
     d = datetime.__add__(self, time)
     return date(d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond, self.format)
Example #19
0
 def __add__(self, arg):        
     if isinstance(arg, int) or isinstance(arg, long) or isinstance(arg, float):
         offset = arg         
     key = {"seconds": offset}
     dt = datetime.__add__(self, timedelta(**key))
     return self._fromDateTime(dt)
Example #20
0
 def fromutc(self, dt):  # type: (_D) -> _D
     # Use the stdlib datetime's add method to avoid infinite recursion
     return (datetime.__add__(dt, self._utcoffset)).replace(tzinfo=self)
Example #21
0
 def __add__(self, other):
     """Add timedelta to gpsdatetime."""
     crn = datetime.__add__(self.replace(tzinfo=None), other)
     return self.copydt(crn, self.tzinfo)