Check if an array contains cftime.datetime objects
555457
def _contains_cftime_datetimes(array) -> bool:
    
    try:
        from cftime import datetime as cftime_datetime
    except ImportError:
        return False
    else:
        if array.dtype == np.dtype('O') and array.size > 0:
            sample = array.ravel()[0]
            if isinstance(sample, dask_array_type):
                sample = sample.compute()
                if isinstance(sample, np.ndarray):
                    sample = sample.item()
            return isinstance(sample, cftime_datetime)
        else:
            return False
22800
def validate(self, obj, **kwargs):
        """"""
        obj = stringify(obj)
        if obj is None:
            return False
        return self.DATE_RE.match(obj) is not None
756360
function contains(array, value) {
    var result = false;
    each(array, function (item) {
        result = item === value;
        return !result;
    });

    return result;
}
195365
def contains(self, time: datetime.datetime,
                 inclusive: bool = True) -> bool:
        
        if inclusive:
            return self.start <= time <= self.end
        else:
            return self.start < time < self.end
406485
def absdatetime(ts, default=None):
    """"""
    if ts is None:
        ts = default
    if isinstance(ts, dict):
        ts = timedelta(**ts)
    if isinstance(ts, timedelta):
        ts = now() + ts
    if isinstance(ts, datetime):
        return ts
    return None
717695
def validate(self, instance, value):
        """"""
        if isinstance(value, datetime.datetime):
            return value
        if not isinstance(value, string_types):
            self.error(
                instance=instance,
                value=value,
                extra='Cannot convert non-strings to datetime.',
            )
        try:
            return self.from_json(value)
        except ValueError:
            self.error(
                instance=instance,
                value=value,
                extra='Invalid format for converting to datetime.',
            )
633203
public static function getAverageTimeForArrayOfDateTimes($array)
    {
        if (!is_array($array)) {
            return false;
        }

        $averageTime = null;

        $averageSecondsFromDateBeginSum = 0;
        $processedItemsCounter = 0;

        foreach ($array as $datetime) {
            if (!is_object($datetime) || !($datetime instanceof \DateTime)) {
                continue;
            }

            $hours = (int)$datetime->format('H');
            $minutes = (int)$datetime->format('i');
            $seconds = (int)$datetime->format('s');

            $averageSecondsFromDateBeginSum += $hours * 3600 + $minutes * 60 + $seconds;
            $processedItemsCounter += 1;
        }

        $averageTime = gmdate('H:i:s', intval($averageSecondsFromDateBeginSum / $processedItemsCounter) % 86400);

        return $averageTime;
    }
814834
function _isArrayOfObjects(value) {
  if (!Array.isArray(value)) {
    return false;
  }
  var l = value.length;
  var _type, cond;
  for (var i = 0; i < l; i++) {
    _type = typeof value[i];
    cond = _type === 'function' || _type === 'object' && !!value[i];
    if (!cond) {
      return false;
    }
  }
  return true;
}
426763
def get_dtype_kinds(l):
    

    typs = set()
    for arr in l:

        dtype = arr.dtype
        if is_categorical_dtype(dtype):
            typ = 'category'
        elif is_sparse(arr):
            typ = 'sparse'
        elif isinstance(arr, ABCRangeIndex):
            typ = 'range'
        elif is_datetime64tz_dtype(arr):
            # if to_concat contains different tz,
            # the result must be object dtype
            typ = str(arr.dtype)
        elif is_datetime64_dtype(dtype):
            typ = 'datetime'
        elif is_timedelta64_dtype(dtype):
            typ = 'timedelta'
        elif is_object_dtype(dtype):
            typ = 'object'
        elif is_bool_dtype(dtype):
            typ = 'bool'
        elif is_extension_array_dtype(dtype):
            typ = str(arr.dtype)
        else:
            typ = dtype.kind
        typs.add(typ)
    return typs
135995
def check_is_dataarray(comp):
    """

    @wraps(comp)
    def func(data_array, *args, **kwds):
        assert isinstance(data_array, xr.DataArray)
        return comp(data_array, *args, **kwds)

    return func
788170
function(value) {
		"use strict";

		if (!Array.isArray(value)) {
			value = [value];
		}

		return value.map(function(data) {
			if (data === "now") {
				return new Date();
			}
			if (data instanceof Date) {
				return data;
			}
			return false;
		}).filter(function(d) { return d !== false; });
	}
1289938
def datetime_match(data, dts):
    
    dts = dts if islistable(dts) else [dts]
    if any([not isinstance(i, datetime.datetime) for i in dts]):
        error_msg = (
            "`time` can only be filtered by datetimes"
        )
        raise TypeError(error_msg)
    return data.isin(dts)
173017
def _sub_datetime_arraylike(self, other):
        """"""
        if len(self) != len(other):
            raise ValueError("cannot add indices of unequal length")

        if isinstance(other, np.ndarray):
            assert is_datetime64_dtype(other)
            other = type(self)(other)

        if not self._has_same_tz(other):
            # require tz compat
            raise TypeError("{cls} subtraction must have the same "
                            "timezones or no timezones"
                            .format(cls=type(self).__name__))

        self_i8 = self.asi8
        other_i8 = other.asi8
        arr_mask = self._isnan | other._isnan
        new_values = checked_add_with_arr(self_i8, -other_i8,
                                          arr_mask=arr_mask)
        if self._hasnans or other._hasnans:
            new_values[arr_mask] = iNaT
        return new_values.view('timedelta64[ns]')
238341
def mean(array, axis=None, skipna=None, **kwargs):
    """"""
    from .common import _contains_cftime_datetimes

    array = asarray(array)
    if array.dtype.kind in 'Mm':
        offset = min(array)
        # xarray always uses np.datetime64[ns] for np.datetime64 data
        dtype = 'timedelta64[ns]'
        return _mean(datetime_to_numeric(array, offset), axis=axis,
                     skipna=skipna, **kwargs).astype(dtype) + offset
    elif _contains_cftime_datetimes(array):
        if isinstance(array, dask_array_type):
            raise NotImplementedError(
                'Computing the mean of an array containing '
                'cftime.datetime objects is not yet implemented on '
                'dask arrays.')
        offset = min(array)
        timedeltas = datetime_to_numeric(array, offset, datetime_unit='us')
        mean_timedeltas = _mean(timedeltas, axis=axis, skipna=skipna,
                                **kwargs)
        return _to_pytimedelta(mean_timedeltas, unit='us') + offset
    else:
        return _mean(array, axis=axis, skipna=skipna, **kwargs)
350477
def isnat(obj):
    
    if obj.dtype.kind not in ('m', 'M'):
        raise ValueError("%s is not a numpy datetime or timedelta")
    return obj.view(int64_dtype) == iNaT
500611
function(input, onlyPrimitives, options) {
  if (
    typeof input === 'boolean' ||
    typeof input === 'number' ||
    typeof input === 'function' ||
    input === null ||
    input instanceof Date
  ) {
    return true;
  }
  if (typeof input === 'string' && input.indexOf('\n') === -1) {
    return true;
  }

  if (options.inlineArrays && !onlyPrimitives) {
    if (Array.isArray(input) && isSerializable(input[0], true, options)) {
      return true;
    }
  }

  return false;
}
694549
def _has_instance(data, dtype):
    """"""
    for item in data:
        _, arr = item
        if isinstance(arr, dtype):
            return True
    return False