Esempio n. 1
0
  @Override
  public int compare(LogEvent o1, LogEvent o2) {
    LocalDateTime t1 = o1.getTime();
    LocalDateTime t2 = o2.getTime();

    if (t1.isBefore(t2)) return 1;
    else if (t1.isAfter(t2)) return -1;
    return 0;
  }
  @Override
  public List<UnidadeIndiceOEE> gerarUnidadesIndiceOEE(
      IndiceOEEPorHoraFilter filter, LocalDateTime dtHrInicio, LocalDateTime dtHrFim) {
    if (dtHrFim == null) {
      LocalTime horaAtual = new LocalTime();
      dtHrFim =
          new LocalDate()
              .toLocalDateTime(
                  new LocalTime(horaAtual.getHourOfDay(), horaAtual.getMinuteOfHour(), 0, 0));
    }
    List<UnidadeIndiceOEE> result = new ArrayList<UnidadeIndiceOEE>();

    int year = dtHrInicio.getYear();
    int month = dtHrInicio.getMonthOfYear();
    int day = dtHrInicio.getDayOfMonth();
    int hour = dtHrInicio.getHourOfDay();

    LocalDateTime dtHr = new LocalDateTime(year, month, day, hour, 0, 0, 0);

    while (dtHr.isBefore(dtHrFim)) {
      if (dtHr.toLocalDate().equals(filter.getDt())) {

        UnidadeIndiceOEE unidade = new UnidadeIndiceOEE();
        unidade.setInicio(dtHr);
        unidade.setFim(dtHr.plusMinutes(59));
        updateId(unidade);

        LocalDateTime inicio = dtHrInicio.isAfter(dtHr) ? dtHrInicio : unidade.getInicio();
        LocalDateTime fim = dtHr.plusHours(1);
        fim = dtHrFim.isAfter(fim) ? fim : dtHrFim;
        Integer tempoUtilMinutos = DateUtils.getDiferencaEmMinutos(inicio, fim);
        unidade.setTempoUtilMinutos(tempoUtilMinutos);

        result.add(unidade);
      }
      dtHr = dtHr.plusHours(1);
    }

    return result;
  }
Esempio n. 3
0
  /**
   * Validate input. Only description can be empty. Start date can not be after end date. Method
   * shows proper error message.
   *
   * @return true if input is proper, false otherwise
   */
  public boolean ValidateForm() {
    String errorMsg = "";
    StringValidator validator = new StringValidator();
    errorMsg += validator.isEmpty("Title", tbTitle.getText().toString());
    errorMsg += validator.isEmpty("Place", tbPlace.getText().toString());
    errorMsg += validator.isEmpty("Start date", tbStartDate.getText().toString());
    errorMsg += validator.isEmpty("End date", tbEndDate.getText().toString());
    errorMsg += validator.isEmpty("Start time", tbStartTime.getText().toString());
    errorMsg += validator.isEmpty("End time", tbEndTime.getText().toString());

    LocalDateTime startFinalDate = startDate.toLocalDateTime(startTime);
    LocalDateTime endFinalDate = endDate.toLocalDateTime(endTime);

    if (startFinalDate.isAfter(endFinalDate))
      errorMsg += "End date can not be before start date!\n";

    if (errorMsg.length() == 0) return true;
    else {
      ModalService.ShowErrorModal(errorMsg, AddEventActivity.this);
      return false;
    }
  }
Esempio n. 4
0
  public List<TimeSlot> getTimeSlotsForDate(
      LocalDate selectedDate,
      List<CalendarConfig> allCalendarConfigs,
      List<Booking> existingBookings,
      Boolean onlyFutureTimeSlots,
      Boolean preventOverlapping)
      throws CalendarConfigException {

    List<CalendarConfig> calendarConfigs =
        calendarConfigUtil.getCalendarConfigsMatchingDate(allCalendarConfigs, selectedDate);
    Iterator<CalendarConfig> iterator = calendarConfigs.iterator();
    while (iterator.hasNext()) {
      CalendarConfig calendarConfig = iterator.next();
      if (isHoliday(selectedDate, calendarConfig)) {
        iterator.remove();
      }
    }

    List<TimeSlot> timeSlots = new ArrayList<>();
    if (calendarConfigs.size() > 0) {
      LocalDate today = new LocalDate(DEFAULT_TIMEZONE);

      // sort all calendar configurations for selected date by start time
      Collections.sort(calendarConfigs);

      CalendarConfig previousConfig = null;
      LocalDateTime time = null;
      LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE);

      // generate list of bookable time slots
      for (CalendarConfig config : calendarConfigs) {
        LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime());
        if (time == null) {
          // on first iteration
          time = startDateTime;
        } else {
          if (time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) {
            // contiguous bookings possible
            // time = time;
          } else {
            // reset basePriceLastConfig as this is a non contiguous offer
            previousConfig = null;
            time = startDateTime;
          }
        }
        LocalDateTime endDateTime = getLocalDateTime(selectedDate, config.getEndTime());
        while (time.plusMinutes(config.getMinDuration()).compareTo(endDateTime) <= 0) {
          BigDecimal pricePerMinDuration;
          if (previousConfig == null) {
            pricePerMinDuration = config.getBasePrice();
          } else {
            BigDecimal previousConfigBasePricePerMinute = getPricePerMinute(previousConfig);
            pricePerMinDuration =
                previousConfigBasePricePerMinute.multiply(
                    new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128);
            BigDecimal basePricePerMinute = getPricePerMinute(config);
            pricePerMinDuration =
                pricePerMinDuration.add(
                    basePricePerMinute.multiply(
                        new BigDecimal(config.getMinDuration() - previousConfig.getMinInterval()),
                        MathContext.DECIMAL128));
            previousConfig = null;
          }
          pricePerMinDuration = pricePerMinDuration.setScale(2, RoundingMode.HALF_EVEN);
          if (onlyFutureTimeSlots) {
            if (selectedDate.isAfter(today) || time.isAfter(now)) {
              addTimeSlot(timeSlots, time, config, pricePerMinDuration);
            }
          } else {
            addTimeSlot(timeSlots, time, config, pricePerMinDuration);
          }
          time = time.plusMinutes(config.getMinInterval());
        }
        previousConfig = config;
      }
      // sort time slots by time
      Collections.sort(timeSlots);

      // decrease court count for every blocking booking
      for (TimeSlot timeSlot : timeSlots) {
        checkForBookedCourts(timeSlot, existingBookings, preventOverlapping);
      }
    }
    return timeSlots;
  }