final public function closest()

in src/datetime/DateTime/Builder.php [65:99]


  final public function closest(): T {
    $month = self::clamp($this->month, 1, 12);
    $day =
      self::clamp($this->day, 1, _DateTime\days_in_month($this->year, $month));
    $hours = self::clamp($this->hours, 0, 23);
    $minutes = self::clamp($this->minutes, 0, 59);
    $seconds = self::clamp($this->seconds, 0, 59);
    $nanoseconds = self::clamp($this->nanoseconds, 0, _DateTime\NS_IN_SEC - 1);

    try {
      return static::instanceFromPartsX(
        $this->timezone,
        $this->year,
        $month,
        $day,
        $hours,
        $minutes,
        $seconds,
        $nanoseconds,
      );
    } catch (Exception $_) {
      // During DST changes clock moves forward by 1 hour, so one specific
      // $hours value is invalid.
      return static::instanceFromPartsX(
        $this->timezone,
        $this->year,
        $month,
        $day,
        $hours + 1,
        $minutes,
        $seconds,
        $nanoseconds,
      );
    }
  }