returns the index of given or best fitting date
15105
def _getFromDate(l, date):
    '''
    
    '''
    try:
        date = _toDate(date)
        i = _insertDateIndex(date, l) - 1
        if i == -1:
            return l[0]
        return l[i]
    except (ValueError, TypeError):
        # ValueError: date invalid / TypeError: date = None
        return l[0]
166888
def _lookup(self, timestamp):
        

        idx = search_greater(self._values, timestamp)
        if (idx < len(self._values)
                and math.fabs(self._values[idx][0] - timestamp) < self.EPSILON):
            return idx
        return None
371361
def GetDate(self):
    
    normalized_timestamp = self._GetNormalizedTimestamp()
    if normalized_timestamp is None:
      return None, None, None

    number_of_days, _, _, _ = self._GetTimeValues(normalized_timestamp)

    try:
      return self._GetDateValuesWithEpoch(
          number_of_days, self._EPOCH_NORMALIZED_TIME)

    except ValueError:
      return None, None, None
355936
static final long getMillisOf(Date date) {
        if (date.cdate == null || date.cdate.isNormalized()) {
            return date.fastTime;
        }
        BaseCalendar.Date d = (BaseCalendar.Date) date.cdate.clone();
        return gcal.getTime(d);
    }
804375
def mean_date(dt_list):
    
    dt_list_sort = sorted(dt_list)
    dt_list_sort_rel = [dt - dt_list_sort[0] for dt in dt_list_sort]
    avg_timedelta = sum(dt_list_sort_rel, timedelta())/len(dt_list_sort_rel)
    return dt_list_sort[0] + avg_timedelta
938681
def ActiveDates(self):
    """"""
    (earliest, latest) = self.GetDateRange()
    if earliest is None:
      return []
    dates = []
    date_it = util.DateStringToDateObject(earliest)
    date_end = util.DateStringToDateObject(latest)
    delta = datetime.timedelta(days=1)
    while date_it <= date_end:
      date_it_string = date_it.strftime("%Y%m%d")
      if self.IsActiveOn(date_it_string, date_it):
        dates.append(date_it_string)
      date_it = date_it + delta
    return dates
1140111
function calculateDatePos(startDayOfMonth, day) {
	const start = startDayOfMonth - 1;
	day = day - 1;
	const weekDayIndex = (start + day) % WEEKDAYS;
	const weekIndex = Math.ceil((start + day + 1) / WEEKDAYS) - 1;
	return {
		weekIndex,
		weekDayIndex
	};
}
1252355
def get_first_date_of_index(elastic_url, index):
    """"""
    es = Elasticsearch(elastic_url)
    search = Search(using=es, index=index)
    agg = A("min", field="grimoire_creation_date")
    search.aggs.bucket("1", agg)
    search = search.extra(size=0)
    response = search.execute()
    start_date = response.to_dict()['aggregations']['1']['value_as_string'][:10]
    return start_date
1150611
def _get_date(data, position, dummy, opts):
    """"""
    end = position + 8
    millis = _UNPACK_LONG(data[position:end])[0]
    diff = ((millis % 1000) + 1000) % 1000
    seconds = (millis - diff) / 1000
    micros = diff * 1000
    if opts.tz_aware:
        return EPOCH_AWARE + datetime.timedelta(
            seconds=seconds, microseconds=micros), end
    else:
        return EPOCH_NAIVE + datetime.timedelta(
            seconds=seconds, microseconds=micros), end
902855
def find_best_rsquared(list_of_fits):
        """"""
        res = sorted(list_of_fits, key=lambda x: x.rsquared)
        return res[-1]
1062634
def onOffset(self, date):
        """"""
        return date.day == _days_in_month(date) and date.month == self.month
275938
private static Integer getEarliestTimestampLineIndex(List<LineAndTime> lines) {
		Integer i = 0;
		for (LineAndTime line : lines) {
			if (isExactEarthTimestamp(line.getLine()))
				return i;
			else
				i++;
		}
		return null;
	}
800708
def extractDate(self, inp):
        """"""
        dates = self.extractDates(inp)
        for date in dates:
            return date
        return None
1080975
def get_index(self, index, type, alias=None, typed=None, read_only=True, kwargs=None):
        
        if kwargs.tjson != None:
            Log.error("used `typed` parameter, not `tjson`")
        if read_only:
            # GET EXACT MATCH, OR ALIAS
            aliases = wrap(self.get_aliases())
            if index in aliases.index:
                pass
            elif index in aliases.alias:
                match = [a for a in aliases if a.alias == index][0]
                kwargs.alias = match.alias
                kwargs.index = match.index
            else:
                Log.error("Can not find index {{index_name}}", index_name=kwargs.index)
            return Index(kwargs=kwargs, cluster=self)
        else:
            # GET BEST MATCH, INCLUDING PROTOTYPE
            best = self.get_best_matching_index(index, alias)
            if not best:
                Log.error("Can not find index {{index_name}}", index_name=kwargs.index)

            if best.alias != None:
                kwargs.alias = best.alias
                kwargs.index = best.index
            elif kwargs.alias == None:
                kwargs.alias = kwargs.index
                kwargs.index = best.index

            return Index(kwargs=kwargs, cluster=self)
1151353
public static Integer getQuarter(Date date) {

        if (date == null)
            return null;

        int season = 1;
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH);
        switch (month) {
            case Calendar.APRIL:
            case Calendar.MAY:
            case Calendar.JUNE:
                season = 2;
                break;
            case Calendar.JULY:
            case Calendar.AUGUST:
            case Calendar.SEPTEMBER:
                season = 3;
                break;
            case Calendar.OCTOBER:
            case Calendar.NOVEMBER:
            case Calendar.DECEMBER:
                season = 4;
                break;
        }
        return season;
    }
21240
function getDatePos(date, month, notValue = null) {
	const monthPos = (date.month === month.date.month && 'current') ||
		(date.month === month.nextMonth.date.month && 'next') ||
		(date.month === month.previousMonth.date.month && 'prev');
		
	switch (monthPos) {
		case 'current':
			return calculateDatePos(month.startDayOfMonth, date.day);
		case 'prev':
			return calculateDatePosinPrev(
				month.startDayOfMonth,
				month.previousMonth.daysCount,
				date.day
			);
		case 'next':
			const posNext = calculateDatePosinNext(
				month.startDayOfMonth,
				month.daysCount,
				date.day
			);

			return posNext;

		default:
			return notValue;
	}
}
1212346
def _doy_to_datetimeindex(doy, epoch_year=2014):
    
    doy = np.atleast_1d(doy).astype('float')
    epoch = pd.Timestamp('{}-12-31'.format(epoch_year - 1))
    timestamps = [epoch + dt.timedelta(days=adoy) for adoy in doy]
    return pd.DatetimeIndex(timestamps)