Returns a delta based on this widget's information.
        
        :return     <datetime.timedelta>
349567
def delta(self):
        
        number      = self._numberSpinner.value()
        unit        = self._unitCombo.currentText()
        direction   = self._directionCombo.currentText()
        
        # use past tense
        if direction == 'ago':
            number = -number
        
        if unit == 'year(s)':
            return datetime.timedelta(number * 365)
        elif unit == 'month(s)':
            return datetime.timedelta(number * 30)
        elif unit == 'week(s)':
            return datetime.timedelta(number * 7)
        elif unit == 'day(s)':
            return datetime.timedelta(number)
        elif unit == 'hour(s)':
            return datetime.timedelta(0, number * 3600)
        elif unit == 'minute(s)':
            return datetime.timedelta(0, number * 60)
        else:
            return datetime.timedelta(0, number)
281312
def subtract_timedelta(self, delta):
        
        if delta.days:
            raise TypeError("Cannot subtract timedelta with days to Time.")

        return self.subtract(seconds=delta.seconds, microseconds=delta.microseconds)
856124
def delta(d1, d2, opt='d'):
    
    delta = 0

    if opt == 'm':
        while True:
            mdays = monthrange(d1.year, d1.month)[1]
            d1 += timedelta(days=mdays)
            if d1 <= d2:
                delta += 1
            else:
                break
    else:
        delta = (d2 - d1).days

    return delta
521337
public long getTimeDelta ()
    {
        if (_iter == 0) { // no responses yet
            return 0L;
        }

        // Return a median value as our estimate, rather than an average.
        // Mdb writes:
        // -----------
        // I used the median because that was more likely to result in a
        // sensible value.
        //
        // Assuming there are two kinds of packets, one that goes and comes
        // back without delay and provides an accurate time value, and one
        // that gets delayed somewhere on the way there or the way back and
        // provides an inaccurate time value.
        //
        // If no packets are delayed, both algorithms should be fine. If one
        // packet is delayed the median will select the middle, non-delayed
        // packet, whereas the average will skew everything a bit because
        // of the delayed packet. If two packets are delayed, the median
        // will be more skewed than the average because it will benefit
        // from the one accurate packet and if all three packets are delayed
        // both algorithms will be (approximately) equally inaccurate.
        //
        // I believe the chances are most likely that zero or one packets
        // will be delayed, so I chose the median rather than the average.
        // -----------

        // copy the deltas array so that we don't alter things before
        // all pongs have arrived
        long[] deltasCopy = new long[_iter];
        System.arraycopy(_deltas, 0, deltasCopy, 0, _iter);

        // sort the estimates and return one from the middle
        Arrays.sort(deltasCopy);
        return deltasCopy[deltasCopy.length/2];
    }
625975
def _get_deltas(event):
        """"""
        delta_x = round(event.deltaX())
        delta_y = round(event.deltaY())
        delta_z = round(event.deltaZ())
        return delta_x, delta_y, delta_z
808562
def ToTimedelta(self):
    """"""
    return timedelta(
        seconds=self.seconds, microseconds=_RoundTowardZero(
            self.nanos, _NANOS_PER_MICROSECOND))
1226768
def _move_datetime(dt, direction, delta):
    
    if direction == 'next':
        dt = dt + delta
    elif direction == 'last':
        dt = dt - delta
    else:
        pass
        # raise some delorean error here
    return dt
803802
def _add_timedelta(self, delta):
        
        if isinstance(delta, pendulum.Period):
            return self.add(
                years=delta.years,
                months=delta.months,
                weeks=delta.weeks,
                days=delta.remaining_days,
                hours=delta.hours,
                minutes=delta.minutes,
                seconds=delta.remaining_seconds,
                microseconds=delta.microseconds,
            )
        elif isinstance(delta, pendulum.Duration):
            return self.add(
                years=delta.years, months=delta.months, seconds=delta.total_seconds()
            )

        return self.add(seconds=delta.total_seconds())
757693
def get_duration(self, seconds=False):
        
        if seconds:
            return str(self.duration)
        delta = datetime.timedelta(seconds=self.duration)
        return str(delta)
1042037
def hours(self,local=False):
        
        delta = self.delta(local)
        return delta.total_seconds()/3600
201781
def set_deltatime(self, delta_time):
        
        if type(delta_time) == int:
            delta_time = self.int_to_varbyte(delta_time)
        self.delta_time = delta_time
1234589
def getDateFromToday(delta,strfmt='%Y%m%d'):
	
	return (dt.date.today() + dt.timedelta(delta)).strftime(strfmt)
18710
def get_delta(value):
    
    if isinstance(value, (int, float)):
        return timedelta(seconds=value)
    elif isinstance(value, timedelta):
        return value
    raise Exception('Invalid delta')
709543
def normalize(self, dt):
        
        if dt is None:
            return None

        dt = self._convert_to_dt(dt)

        dt = dt.replace(microsecond=0)  # remove microseconds, to avoid float rounding issues.
        delta = (dt - self.start).total_seconds()
        granularity = (self._timedelta * self.interval).total_seconds()
        return dt - datetime.timedelta(seconds=delta % granularity)
579390
def calculate_delta_date(literal):
    
    mapping = {
        "today": 0,
        "yesterday": 1,
        "this-week": 7,
        "this-month": 30,
        "this-year": 365,
    }
    today = DateTime(DateTime().Date())  # current date without the time
    return today - mapping.get(literal, 0)
273805
def time_delta(self, end_datetime=None):
        
        start_datetime = self._parse_start_datetime('now')
        end_datetime = self._parse_end_datetime(end_datetime)
        seconds = end_datetime - start_datetime

        ts = self.generator.random.randint(*sorted([0, seconds]))
        return timedelta(seconds=ts)
423732
def timestamp_from_dt(dt, epoch=datetime(1970, 1, 1)):
    
    delta = dt - epoch
    # return delta.total_seconds()
    return delta.seconds + delta.days * 86400