code: def _extend_time_index(
      time_index: pd.Index,
      freq: Union[int, str],
      new_start: Optional[pd.Timestamp] = None,
      new_end: Optional[pd.Timestamp] = None,
  ):
      """
      Extends a `time_index` of frequency `freq` such that it now ends at time `new_end`;
      the fastest way to do this is actually to create a new time index from scratch.
      """
      is_range_idx = isinstance(freq, int)
      if new_start is None:
          new_start = time_index[0]
      if new_end is None:
          new_end = time_index[-1]
      if is_range_idx:
          time_index = pd.RangeIndex(
              start=new_start, stop=new_end + freq, step=freq
          )
      else:
          time_index = pd.date_range(
              start=new_start, end=new_end, freq=freq
          )
      return time_index
  
imports: import warnings
  from functools import reduce
  from math import inf
  from typing import Dict, List, Optional, Sequence, Tuple, Union
  from itertools import chain
  import numpy
  import pandas
  from numpy.lib.stride_tricks import as_strided
  from darts.logging import get_logger, raise_if, raise_if_not, raise_log
  from darts.timeseries import TimeSeries
  from darts.utils.utils import get_single_series, series2seq
label_desc: Use image node_id 13 for calling a global function with example usage: _extend_time_index(time_index, freq, new_start, new_end) and returns: time_index