code: public static TimeSeries subseries(TimeSeries series, int beginIndex, Duration duration) {
  
          // Calculating the sub-series interval
          ZonedDateTime beginInterval = series.getTick(beginIndex).getEndTime();
          ZonedDateTime endInterval = beginInterval.plus(duration);
  
          // Checking ticks belonging to the sub-series (starting at the provided index)
          int subseriesNbTicks = 0;
          int endIndex = series.getEndIndex();
          for (int i = beginIndex; i <= endIndex; i++) {
              // For each tick...
              ZonedDateTime tickTime = series.getTick(i).getEndTime();
              if (tickTime.isBefore(beginInterval) || !tickTime.isBefore(endInterval)) {
                  // Tick out of the interval
                  break;
              }
              // Tick in the interval
              // --> Incrementing the number of ticks in the subseries
              subseriesNbTicks++;
          }
  
          return new BaseTimeSeries(series, beginIndex, beginIndex + subseriesNbTicks - 1);
      }
docs: Returns a new time series which is a view of a subset of the current series.
  <p>
  The new series has begin and end indexes which correspond to the bounds of the sub-set into the full series.<br>
  The tick of the series are shared between the original time series and the returned one (i.e. no copy).
  @param series the time series to get a sub-series of
  @param beginIndex the begin index (inclusive) of the time series
  @param duration the duration of the time series
  @return a constrained {@link TimeSeries time series} which is a sub-set of the current series