コード例 #1
0
  private void validateIntervalDuration(ConferenceInterval interval) {
    LocalDateTime startDateTime = interval.getStartDateTime();
    LocalDateTime endDateTime = interval.getEndDateTime();

    long hours = startDateTime.until(endDateTime, ChronoUnit.HOURS);

    if (hours < MIN_CONFERENCE_DURATION_IN_HOURS) {
      throw new ValidationException(
          String.format(
              "Conference duration is %s hours, less than min of %s hour(s)",
              hours, MIN_CONFERENCE_DURATION_IN_HOURS));
    }

    long days = startDateTime.until(endDateTime, ChronoUnit.DAYS);

    if (days > MAX_CONFERENCE_DURATION_IN_DAYS) {
      throw new ValidationException(
          String.format(
              "Conference duration is %s days, more than max of %s day(s)",
              days, MAX_CONFERENCE_DURATION_IN_DAYS));
    }
  }
コード例 #2
0
  private void validateIntervalPosition(ConferenceInterval interval) {
    LocalDateTime startDateTime = interval.getStartDateTime();
    LocalDateTime endDateTime = interval.getEndDateTime();
    LocalDateTime now = LocalDateTime.now();

    LocalDateTime minStartDateTime = now.plusDays(MIN_TIME_BEFORE_CONFERENCE_START_IN_DAYS);

    if (startDateTime.isBefore(minStartDateTime)) {
      throw new ValidationException(
          String.format(
              "Conference must start after %s",
              minStartDateTime.format(CONFERENCE_DATE_TIME_FORMATTER)));
    }

    if (endDateTime.isBefore(startDateTime)) {
      throw new ValidationException(
          String.format(
              "Conference end dateTime %s is before start dateTime %s",
              endDateTime.format(CONFERENCE_DATE_TIME_FORMATTER),
              startDateTime.format(CONFERENCE_DATE_TIME_FORMATTER)));
    }
  }