def _ensure_datetimelike_to_i8(other, to_utc=False):
from pandas import Index<EOL>from pandas.core.arrays import PeriodArray<EOL>if lib.is_scalar(other) and isna(other):<EOL><INDENT>return iNaT<EOL><DEDENT>elif isinstance(other, (PeriodArray, ABCIndexClass,<EOL>DatetimeLikeArrayMixin)):<EOL><INDENT>if getattr(other, '<STR_LIT>', None) is not None:<EOL><INDENT>if to_utc:<EOL><INDENT>other = other.tz_convert('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>other = other.tz_localize(None)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>return np.array(other, copy=False).view('<STR_LIT>')<EOL><DEDENT>except TypeError:<EOL><INDENT>other = Index(other)<EOL><DEDENT><DEDENT>return other.asi8<EOL>
Helper for coercing an input scalar or array to i8.

Parameters
----------
other : 1d array
to_utc : bool, default False
    If True, convert the values to UTC before extracting the i8 values
    If False, extract the i8 values directly.

Returns
-------
i8 1d array