def __new__(cls, *args, **kwargs): if len(args) == 1 and not kwargs and isinstance(args[0], timedelta): td = args[0] self = timedelta.__new__(cls, td.days, td.seconds, td.microseconds) else: self = timedelta.__new__(cls, *args, **kwargs) return self
def __new__(cls, *a, **kw): format_args = kw.pop('format_args', {}) if len(a) == 1 and not kw and isinstance(a[0], timedelta): r = timedelta.__new__(cls, a[0].days, a[0].seconds, a[0].microseconds) else: r = timedelta.__new__(cls, *a, **kw) r.format_args = format_args return r
def __new__(cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0): self = timedelta.__new__(cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks) # We need to compute the total_seconds() value # on a native timedelta object delta = timedelta(days, seconds, microseconds, milliseconds, minutes, hours, weeks) # Intuitive normalization self._total = delta.total_seconds() total = abs(self._total) self._microseconds = round(total % 1 * 1e6) self._seconds = int(total) % SECONDS_PER_DAY self._days = int(total) // SECONDS_PER_DAY return self
def __new__(cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0, years=0, months=0): if not isinstance(years, int) or not isinstance(months, int): raise ValueError('Float year and months are not supported') self = timedelta.__new__( cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # Intuitive normalization total = self.total_seconds() m = 1 if total < 0: m = -1 self._microseconds = round(total % m * 1e6) self._seconds = abs(int(total)) % SECONDS_PER_DAY * m _days = abs(int(total)) // SECONDS_PER_DAY * m self._days = _days + (years * 365 + months * 30) self._remaining_days = abs(_days) % 7 * m self._weeks = abs(_days) // 7 * m self._months = months self._years = years return self
def __new__(cls, desc): """Since we derive from timedelta which is special, we must use __new__. """ if isinstance(desc, timedelta): kwargs = { 'days': desc.days , 'seconds': desc.seconds , 'microseconds': desc.microseconds } elif desc == 'now': kwargs = {} else: parts = desc.split(' ') ago = False if parts[-1] == 'ago': parts = parts[:-1] ago = True kwargs = {} for i in range(0, len(parts), 2): qty = float(parts[i]) if ago: qty = -qty unit = parts[i + 1] if unit[-1] == 's': unit = unit[:-1] unit = unit + "s" kwargs[unit] = qty instance = timedelta.__new__(TimeInterval, **kwargs) return instance
def __new__(cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0, years=0, months=0): if not isinstance(years, int) or not isinstance(months, int): raise ValueError('Float year and months are not supported') self = timedelta.__new__( cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # We need to compute the total_seconds() value # on a native timedelta object delta = timedelta( days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # Intuitive normalization self._total = delta.total_seconds() total = abs(self._total) self._microseconds = round(total % 1 * 1e6) self._seconds = int(total) % SECONDS_PER_DAY days = int(total) // SECONDS_PER_DAY self._days = abs(days + years * 365 + months * 30) self._remaining_days = days % 7 self._weeks = days // 7 self._months = abs(months) self._years = abs(years) return self
def __new__(cls, tm): if isinstance(tm, timedelta): return timedelta.__new__( cls, days=tm.days, seconds=tm.seconds, microseconds=tm.microseconds )
def new_object(totaled_days): td_cls = cls if td_cls is None: td_cls = timedelta return timedelta.__new__(td_cls, days=totaled_days, seconds=seconds, microseconds=microseconds, milliseconds=milliseconds, minutes=minutes, hours=hours, weeks=weeks)
def __new__(cls, *args, **kwargs): """ A convenience wrapper for datetime.timedelta that handles months and years. """ # Time.years # Time.months # Time.days # Time.seconds # Time.microseconds y = kwargs.pop("years", 0) m = kwargs.pop("months", 0) t = timedelta.__new__(cls, *args, **kwargs) setattr(t, "years", y) setattr(t, "months", m) return t
def __new__(cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0): self = timedelta.__new__(cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks) # Intuitive normalization total = abs(self.total_seconds()) self._microseconds = round(total % 1 * 1e6) self._seconds = int(total) % SECONDS_PER_DAY self._days = int(total) // SECONDS_PER_DAY return self
def __new__(cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0): self = timedelta.__new__( cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # Intuitive normalization total = self.total_seconds() m = 1 if total < 0: m = -1 self._microseconds = abs(round(total % 1 * 1e6)) * m self._seconds = abs(int(total)) % SECONDS_PER_DAY * m self._days = abs(int(total)) // SECONDS_PER_DAY * m return self
def __new__( cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0, years=0, months=0, ): if not isinstance(years, int) or not isinstance(months, int): raise ValueError("Float year and months are not supported") self = timedelta.__new__( cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # We need to compute the total_seconds() value # on a native timedelta object delta = timedelta( days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # Intuitive normalization self._total = delta.total_seconds() total = abs(self._total) self._microseconds = round(total % 1 * 1e6) self._seconds = int(total) % SECONDS_PER_DAY days = int(total) // SECONDS_PER_DAY self._days = abs(days + years * 365 + months * 30) self._remaining_days = days % 7 self._weeks = days // 7 self._months = abs(months) self._years = abs(years) return self
def __new__( cls, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0, years=0, months=0, ): if not isinstance(years, int) or not isinstance(months, int): raise ValueError("Float year and months are not supported") self = timedelta.__new__( cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks ) # Intuitive normalization total = self.total_seconds() m = 1 if total < 0: m = -1 self._microseconds = round(total % m * 1e6) self._seconds = abs(int(total)) % SECONDS_PER_DAY * m _days = abs(int(total)) // SECONDS_PER_DAY * m self._days = _days + (years * 365 + months * 30) self._remaining_days = abs(_days) % 7 * m self._weeks = abs(_days) // 7 * m self._months = months self._years = years return self
def __new__(*args, **kwargs): # pylint: disable=no-method-argument if len(args) == 2 and isinstance(args[1], (timedelta, np.timedelta64)): return timedelta.__new__(args[0], args[1].days, args[1].seconds, args[1].microseconds) else: return timedelta.__new__(*args, **kwargs)
def __new__(cls, tm): if isinstance(tm, timedelta): return timedelta.__new__(cls, days=tm.days, seconds=tm.seconds, microseconds=tm.microseconds)
def __new__(cls, *a, **kw): if len(a) == 1 and not kw and isinstance(a[0], timedelta): return timedelta.__new__(cls, a[0].days, a[0].seconds, a[0].microseconds) return timedelta.__new__(cls, *a, **kw)
def __new__(cls, hours, minutes): return timedelta.__new__(cls, hours=hours, minutes=minutes)
def __new__(cls, time_delta: timedelta, *_, **__): if time_delta: return timedelta.__new__(cls, days=time_delta.days, seconds=time_delta.seconds) return timedelta.__new__(cls)
def __new__(cls, minutes=0, seconds=0): seconds = minutes * 60 + seconds seconds = min(90 * 60, seconds) seconds = max(0, seconds) self = timedelta.__new__(cls, seconds=seconds) return self