code: def _get_duration(x, y=None, coerce_to_int=False, unit=None):
      """Compute duration between the time indices.
  
      Parameters
      ----------
      x : pd.Index, pd.Timestamp, pd.Period, int
      y : pd.Timestamp, pd.Period, int, optional (default=None)
      coerce_to_int : bool
          If True, duration is returned as integer value for given unit
      unit : str
          Time unit
  
      Returns
      -------
      ret : duration type
          Duration
      """
      if y is None:
          x = check_time_index(x)
          duration = x[-1] - x[0]
      else:
          assert isinstance(
              x, (int, np.integer, pd.Period, pd.Timestamp)
          )
          # check types allowing (np.integer, int) combinations to pass
          assert type(x) is type(y) or (
              isinstance(x, (np.integer, int))
              and isinstance(x, (np.integer, int))
          )
          duration = x - y
  
      # coerce to integer result for given time unit
      if coerce_to_int and isinstance(
          x, (pd.PeriodIndex, pd.DatetimeIndex, pd.Period, pd.Timestamp)
      ):
          if unit is None:
              # try to get the unit from the data if not given
              unit = _get_freq(x)
          duration = _coerce_duration_to_int(duration, freq=unit)
      return duration
  
file_path: sktime/sktime/utils/datetime.py
imports: import warnings
  from functools import singledispatch
  from typing import Optional, Tuple, Union
  import numpy
  import pandas
  from sktime.datatypes import VectorizedDF
  from sktime.datatypes._utilities import get_time_index
  from sktime.utils.validation.series import check_time_index, is_integer_index
label_desc: Use image node_id 10 for calling a global function with example usage: _get_duration(x, y, coerce_to_int, unit) and returns: duration