code: def _extend_time_index_until(
      time_index: Union[pd.DatetimeIndex, pd.RangeIndex],
      until: Optional[Union[int, str, pd.Timestamp]],
      add_length: int,
  ) -> pd.DatetimeIndex:
      if not add_length and not until:
          return time_index
  
      raise_if(
          bool(add_length) and bool(until),
          "set only one of add_length and until",
      )
  
      end = time_index[-1]
      freq = time_index.freq
  
      if add_length:
          raise_if_not(
              add_length >= 0,
              f"Expected add_length, by which to extend the time series by, "
              f"to be positive, got {add_length}",
          )
  
          try:
              end += add_length * freq
          except pd.errors.OutOfBoundsDatetime:
              raise_log(
                  ValueError(
                      f"the add operation between {end} and {add_length * freq} will overflow"
                  ),
                  logger,
              )
      else:
          datetime_index = isinstance(time_index, pd.DatetimeIndex)
  
          if datetime_index:
              raise_if_not(
                  isinstance(until, (str, pd.Timestamp)),
                  "Expected valid timestamp for TimeSeries, "
                  "indexed by DatetimeIndex, "
                  f"for parameter until, got {type(end)}",
                  logger,
              )
          else:
              raise_if_not(
                  isinstance(until, int),
                  "Expected integer for TimeSeries, indexed by RangeIndex, "
                  f"for parameter until, got {type(end)}",
                  logger,
              )
  
          timestamp = pd.Timestamp(until) if datetime_index else until
  
          raise_if_not(
              timestamp > end,
              f"Expected until, {timestamp} to lie past end of time index {end}",
          )
  
          ahead = timestamp - end
          raise_if_not(
              (ahead % freq) == pd.Timedelta(0),
              f"End date must correspond with frequency {freq} of the time axis",
              logger,
          )
  
          end = timestamp
  
      new_time_index = pd.date_range(
          start=time_index[0], end=end, freq=freq
      )
      return new_time_index
  
file_path: darts/darts/utils/timeseries_generation.py
imports: import math
  from typing import List, Optional, Sequence, Tuple, Union
  import holidays
  import numpy
  import pandas
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not, raise_log
label_desc: Use image node_id 8 for calling a global function with example usage: _extend_time_index_until(time_index, until, add_length) and returns: new_time_index, time_index