計算乖離率（均價）
            date1 - date2

            :param int data1: n 日
            :param int data2: m 日
            :rtype: 序列 舊→新
559042
def ma_bias_ratio(self, date1, date2, data):
        
        data1 = self.moving_average(data, date1)
        data2 = self.moving_average(data, date2)
        cal_list = []
        for i in range(1, min(len(data1), len(data2)) + 1):
            cal_list.append(data1[-i] - data2[-i])
        cal_list.reverse()
        return cal_list
1249679
def dateRect( self, date ):
        
        data = self._dateGrid.get(date.toJulianDay())
        if ( data ):
            return QRectF(data[1])
        return QRectF()
38124
def _date2int(date):
        
        if isinstance(date, str):
            if date.endswith(' 00:00:00') or date.endswith('T00:00:00'):
                # Ignore time suffix.
                date = date[0:-9]
            tmp = datetime.datetime.strptime(date, '%Y-%m-%d')
            return tmp.toordinal()

        if isinstance(date, datetime.date):
            return date.toordinal()

        if isinstance(date, int):
            return date

        raise ValueError('Unexpected type {0!s}'.format(date.__class__))
418355
def value_as_date(self):
        ''' 
        '''
        if self.value is None:
            return None
        v1, v2 = self.value
        if isinstance(v1, numbers.Number):
            dt = datetime.utcfromtimestamp(v1 / 1000)
            d1 = date(*dt.timetuple()[:3])
        else:
            d1 = v1
        if isinstance(v2, numbers.Number):
            dt = datetime.utcfromtimestamp(v2 / 1000)
            d2 = date(*dt.timetuple()[:3])
        else:
            d2 = v2
        return d1, d2
320353
def _build_date(date, kwargs):
    
    if date is None:
        if not kwargs:
            raise ValueError('Must pass a date or kwargs')
        else:
            return datetime.date(**kwargs)

    elif kwargs:
        raise ValueError('Cannot pass kwargs and a date')
    else:
        return date
97725
public static Date addDay(Date date1, int addDay) {
        Date resultDate = null;
        Calendar c = Calendar.getInstance();
        c.setTime(date1); // 设置当前日期
        c.add(Calendar.DATE, addDay); // 日期加1
        resultDate = c.getTime(); // 结果
        return resultDate;
    }
271766
public static int[] getElapsedTime(Date first, Date second) {
         if (first.compareTo(second) == 1 ) {
            return null;
         }
         int difDays = 0;
         int difHours = 0;
         int difMinutes = 0;

         Calendar c = Calendar.getInstance();
         c.setTime(first);
         int h1 = c.get(Calendar.HOUR_OF_DAY);
         int m1 = c.get(Calendar.MINUTE);

         c.setTime(second);
         int h2 = c.get(Calendar.HOUR_OF_DAY);
         int m2 = c.get(Calendar.MINUTE);

         if (sameDay(first, second)) {
             difHours = h2 - h1;
         } else {
             difDays = getNumberOfDays(first, second)-1;
             if (h1 >= h2) {
                difDays--;
                difHours = (24 - h1) + h2;
             } else {
                difHours = h2 - h1;
             }
         }

         if (m1 >= m2) {
             difHours--;
             difMinutes = (60 - m1) + m2;
         } else {
             difMinutes = m2 - m1;
         }

         int[] result = new int[3];
         result[0] = difDays;
         result[1] = difHours;
         result[2] = difMinutes;
         return result;
     }
1038268
public static long subMinutes(final Date date1, final Date date2) {

    return subTime(date1, date2, DatePeriod.MINUTE);
  }
1312639
def _rows_date2int(self, rows):
        
        for row in rows:
            # Determine the type of dates based on the first start date.
            if not self._date_type:
                self._date_type = self._get_date_type(row[self._key_start_date])

            # Convert dates to integers.
            row[self._key_start_date] = self._date2int(row[self._key_start_date])
            row[self._key_end_date] = self._date2int(row[self._key_end_date])
949437
def handle_friday(next_date: Datum, period: str, mult: int, start_date: Datum):
    
    assert isinstance(next_date, Datum)
    assert isinstance(start_date, Datum)

    # Starting from line 220.
    tmp_sat = next_date.clone()
    tmp_sat.add_days(1)

    tmp_sun = next_date.clone()
    tmp_sun.add_days(2)

    if period == RecurrencePeriod.END_OF_MONTH.value:
        if (next_date.is_end_of_month() or tmp_sat.is_end_of_month() or
                tmp_sun.is_end_of_month()):
            next_date.add_months(1)
        else:
            next_date.add_months(mult - 1)
    else:
        if tmp_sat.get_day_name() == start_date.get_day_name():
            next_date.add_days(1)
            next_date.add_months(mult)
        elif tmp_sun.get_day_name() == start_date.get_day_name():
            next_date.add_days(2)
            next_date.add_months(mult)
        elif next_date.get_day() >= start_date.get_day():
            next_date.add_months(mult)
        elif next_date.is_end_of_month():
            next_date.add_months(mult)
        elif tmp_sat.is_end_of_month():
            next_date.add_days(1)
            next_date.add_months(mult)
        elif tmp_sun.is_end_of_month():
            next_date.add_days(2)
            next_date.add_months(mult)
        else:
            # /* one fewer month fwd because of the occurrence in this month */
            next_date.subtract_months(1)

    return next_date
541146
function dateDiff($d1, $d2)
    {
        $date1 = strtotime($d1);
        $date2 = strtotime($d2);
        $seconds = $date1 - $date2;
        $weeks = floor($seconds / 604800);
        $seconds -= $weeks * 604800;
        $days = floor($seconds / 86400);
        $seconds -= $days * 86400;
        $hours = floor($seconds / 3600);
        $seconds -= $hours * 3600;
        $minutes = floor($seconds / 60);
        $seconds -= $minutes * 60;
        $months = round(($date1 - $date2) / 60 / 60 / 24 / 30);
        $years = round(($date1 - $date2) / (60 * 60 * 24 * 365));

        $secs_unit = (abs($seconds) == 1) ? ' Second ' : ' Seconds ';
        $mins_unit = (abs($minutes) == 1) ? ' Minute ' : ' Minutes ';
        $hours_unit = (abs($hours) == 1) ? ' Hour ' : ' Hours ';
        $days_unit = (abs($days) == 1) ? ' Day ' : ' Days ';
        $weeks_unit = (abs($weeks) == 1) ? ' Week ' : ' Weeks ';
        $months_unit = (abs($months) == 1) ? ' Month ' : ' Months ';
        $years_unit = (abs($years) == 1) ? ' Year ' : ' Years ';

        $difference = "";

        if (!empty($years))
            $difference .= $years . $years_unit;
        if (!empty($months))
            $difference .= $months . $months_unit;
        if (!empty($weeks))
            $difference .= $weeks . $weeks_unit;
        if (!empty($days))
            $difference .= $days . $days_unit;
        if (!empty($hours))
            $difference .= $hours . $hours_unit;
        if (!empty($minutes))
            $difference .= $minutes . $mins_unit;
        if (!empty($seconds))
            $difference .= $seconds . $secs_unit;

        return $difference;
    }
214929
def mkIntDate(s):
    
    n = s.__len__()
    d = int(s[-(n - 1):n])

    return d
355115
def iterdays(self, d1, d2):
        
        curr = datetime.datetime.combine(d1, datetime.time())
        end = datetime.datetime.combine(d2, datetime.time())
        if d1.date() == d2.date():
            yield curr
            return
        while curr < end:
            yield curr
            curr = curr + datetime.timedelta(days=1)
265954
def _try_convert_to_date(self, data):
        

        # no conversion on empty
        if not len(data):
            return data, False

        new_data = data
        if new_data.dtype == 'object':
            try:
                new_data = data.astype('int64')
            except:
                pass

        # ignore numbers that are out of range
        if issubclass(new_data.dtype.type, np.number):
            in_range = (isnull(new_data.values) | (new_data > self.min_stamp) |
                        (new_data.values == iNaT))
            if not in_range.all():
                return data, False

        date_units = (self.date_unit,) if self.date_unit else self._STAMP_UNITS
        for date_unit in date_units:
            try:
                new_data = to_datetime(new_data, errors='raise',
                                       unit=date_unit)
            except ValueError:
                continue
            except:
                break
            return new_data, True
        return data, False
175990
def daterange_(self, datecol, date_start, op, **args):
        
        df = self._daterange(datecol, date_start, op, **args)
        if df is None:
            self.err("Can not select date range data")
        return self._duplicate_(df)
182469
public static long subDays(final Date date1, final Date date2) {

    return subTime(date1, date2, DatePeriod.DAY);
  }
44665
function isDayBefore(d1, d2) {
  var day1 = clone(d1).setHours(0, 0, 0, 0);
  var day2 = clone(d2).setHours(0, 0, 0, 0);
  return day1 < day2;
}