Used, for example, where a database backend insists on datetime.datetime.

    Compare code in :meth:`pendulum.datetime.DateTime.int_timestamp`.
19273
def pendulum_to_datetime(x: DateTime) -> datetime.datetime:
    
    return datetime.datetime(
        x.year, x.month, x.day,
        x.hour, x.minute, x.second, x.microsecond,
        tzinfo=x.tzinfo
    )
899681
def TimestampToRDFDatetime(timestamp):
  """"""
  # TODO(hanuszczak): `timestamp` should be of MySQL type `Decimal`. However,
  # it is unclear where this type is actually defined and how to import it in
  # order to have a type assertion.
  if timestamp is None:
    return None
  else:
    micros = int(1000000 * timestamp)
    return rdfvalue.RDFDatetime.FromMicrosecondsSinceEpoch(micros)
263353
def _try_coerce_args(self, values, other):
        

        if isinstance(other, ABCDatetimeIndex):
            # May get a DatetimeIndex here. Unbox it.
            other = other.array

        if isinstance(other, DatetimeArray):
            # hit in pandas/tests/indexing/test_coercion.py
            # ::TestWhereCoercion::test_where_series_datetime64[datetime64tz]
            # when falling back to ObjectBlock.where
            other = other.astype(object)

        return values, other
572303
def _new_DatetimeIndex(cls, d):
    

    if "data" in d and not isinstance(d["data"], DatetimeIndex):
        # Avoid need to verify integrity by calling simple_new directly
        data = d.pop("data")
        result = cls._simple_new(data, **d)
    else:
        with warnings.catch_warnings():
            # we ignore warnings from passing verify_integrity=False
            # TODO: If we knew what was going in to **d, we might be able to
            #  go through _simple_new instead
            warnings.simplefilter("ignore")
            result = cls.__new__(cls, verify_integrity=False, **d)

    return result
1104414
def compare_timestamp(src, dst):
  

  try:
    dst_time = os.path.getmtime(dst)
  except OSError as exc:
    if exc.errno == errno.ENOENT:
      return True  # dst does not exist

  src_time = os.path.getmtime(src)
  return src_time > dst_time
1089464
def get_timerange(self, start, end, code=None):
        
        try:
            return self.data.loc[(slice(pd.Timestamp(start), pd.Timestamp(end)), slice(code)), :]
        except:
            return ValueError('CANNOT FOUND THIS TIME RANGE')
1359058
def timestamp(x):
    """"""
    if x.tzinfo is None:
        # Naive dates to utc
        x = x.replace(tzinfo=utc)

    if hasattr(x, 'timestamp'):
        return x.timestamp()
    else:
        return (x - datetime(1970, 1, 1, tzinfo=utc)).total_seconds()
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
1057511
def pendulum_date_to_datetime_date(x: Date) -> datetime.date:
    
    return datetime.date(year=x.year, month=x.month, day=x.day)
11920
def is_same_day(self, dt):
        
        dt = pendulum.instance(dt)

        return self.to_date_string() == dt.to_date_string()
93975
def coerce_dt_awareness(date_or_datetime, tz=None, t=None):
    
    if isinstance(date_or_datetime, datetime):
        dt = date_or_datetime
    else:
        dt = datetime.combine(date_or_datetime, t or time.min)
    is_project_tz_aware = settings.USE_TZ
    if is_project_tz_aware:
        return coerce_aware(dt, tz)
    elif not is_project_tz_aware:
        return coerce_naive(dt, tz)
    # No changes necessary
    return dt
1061130
def sqlalch_datetime(dt):
    """"""
    if isinstance(dt, str):
        return datetime.strptime(dt, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=UTC)
    if dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None:
        return dt.astimezone(UTC)
    return dt.replace(tzinfo=UTC)
909862
def to_timestamp(self, value):
        
        if isinstance(value, (six.integer_types, float, six.string_types)):
            try:
                return int(value)
            except ValueError:
                value = self.datetime_str_to_datetime(value)

        if isinstance(value, datetime.datetime):
            if timezone.is_aware(value):
                value = timezone.localtime(value, timezone.utc)
            return self._datetime_to_timestamp(value)

        raise exceptions.ValidationError(
            "Unable to convert value: '%s' to timestamp" % value,
            code="invalid_timestamp"
        )
267344
def _validate_datetime(cls, value):
        
        datetime_check = validators.Int()
        datetime_check.to_python(value)
        if len(value) != 8:
            raise MlbAmBadParameter("Length Error:{value}({length})".format(value=value, length=len(value)))
973618
def datetime(self):
        
        try:
            dt = self._tick_dict['datetime']
        except (KeyError, ValueError):
            return datetime.datetime.min
        else:
            if not isinstance(dt, datetime.datetime):
                if dt > 10000000000000000:  # ms
                    return convert_ms_int_to_datetime(dt)
                else:
                    return convert_int_to_datetime(dt)
            return dt
9202
def _timestamp_instants_eq(a, b):
    """"""
    assert isinstance(a, datetime)
    if not isinstance(b, datetime):
        return False
    # datetime's __eq__ can't compare a None offset and a non-None offset. For these equivalence semantics, a None
    # offset (unknown local offset) is treated equivalently to a +00:00.
    if a.tzinfo is None:
        a = a.replace(tzinfo=OffsetTZInfo())
    if b.tzinfo is None:
        b = b.replace(tzinfo=OffsetTZInfo())
    # datetime's __eq__ implementation compares instants; offsets and precision need not be equal.
    return a == b
579784
def QA_util_stamp2datetime(timestamp):
    
    try:
        return datetime.datetime.fromtimestamp(timestamp)
    except Exception as e:
        # it won't work ??
        try:
            return datetime.datetime.fromtimestamp(timestamp / 1000)
        except:
            try:
                return datetime.datetime.fromtimestamp(timestamp / 1000000)
            except:
                return datetime.datetime.fromtimestamp(timestamp / 1000000000)