Example usage for org.joda.time LocalDateTime isAfter

List of usage examples for org.joda.time LocalDateTime isAfter

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime isAfter.

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:de.appsolve.padelcampus.controller.bookings.BookingsController.java

private void validateBookingCancellation(Booking booking) throws Exception {
    if (booking == null) {
        throw new Exception(msg.get("InvalidBooking"));
    }/* w  w w  .j a  va2 s.c  o  m*/
    if (booking.getCancelled()) {
        throw new Exception(msg.get("BookingAlreadyCancelled"));
    }
    if (booking.getOffer() == null) {
        throw new Exception(msg.get("BookingCannotBeCancelled"));
    }
    LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE);
    LocalDateTime bookingTime = new LocalDateTime().withDate(booking.getBookingDate().getYear(),
            booking.getBookingDate().getMonthOfYear(), booking.getBookingDate().getDayOfMonth()).withTime(
                    booking.getBookingTime().getHourOfDay(), booking.getBookingTime().getMinuteOfHour(), 0, 0);
    if (now.isAfter(bookingTime)) {
        throw new Exception(msg.get("BookingCancellationDeadlineMissed"));
    }

    Duration duration = new Duration(now.toDateTime(DateTimeZone.UTC),
            bookingTime.toDateTime(DateTimeZone.UTC));
    if (duration.getStandardHours() < CANCELLATION_POLICY_DEADLINE) {
        throw new Exception(msg.get("BookingCancellationDeadlineMissed"));
    }
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

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);/*from  w ww  .  j  a v  a  2s  .com*/
    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
        int i = 0;
        for (CalendarConfig config : calendarConfigs) {
            i++;
            LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime());
            if (time == null) {
                //on first iteration
                time = startDateTime;
            } else if (!time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) {
                //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());
            }
            //make sure to display the last min interval of the day
            if (config.getMinInterval() < config.getMinDuration() && i == calendarConfigs.size()) {
                if (time.plusMinutes(config.getMinInterval()).compareTo(endDateTime) <= 0) {
                    addTimeSlot(timeSlots, time, config, null);
                }
            }
            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;
}

From source file:net.rrm.ehour.report.reports.element.AssignmentAggregateReportElement.java

License:Open Source License

/**
 * Get the progress (booked hours) in percentage of the allotted hours, leaving out the overrun
 * or for date ranges use the current date vs start & end date (if they're both null)
 *//*  w  ww .j  a va  2s.co m*/
public Optional<Float> getProgressPercentage() {
    Optional<Float> percentage = Optional.absent();

    if (projectAssignment == null) {
        return Optional.absent();
    }

    if (projectAssignment.getAssignmentType().isAllottedType()) {
        if (hours != null && projectAssignment.getAllottedHours() != null && hours.floatValue() > 0
                && projectAssignment.getAllottedHours() > 0) {
            percentage = Optional.of((hours.floatValue() / projectAssignment.getAllottedHours()) * 100);

        }
    } else if (projectAssignment.getAssignmentType().isDateType() && projectAssignment.getDateStart() != null
            && projectAssignment.getDateEnd() != null) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime start = new LocalDateTime(projectAssignment.getDateStart());
        LocalDateTime end = new LocalDateTime(projectAssignment.getDateEnd());

        if (now.isBefore(start)) {
            percentage = Optional.of(0f);
        } else if (now.isAfter(end)) {
            percentage = Optional.of(100f);
        } else {
            float totalRange = Days.daysBetween(start, end).getDays();
            float daysConsumed = Days.daysBetween(start, now).getDays();

            percentage = Optional.of((daysConsumed / totalRange) * 100);
        }

        // if percentage is above 100 for daterange the user can't book anymore hours
        // so don't display more than 100%
        if (percentage.get() > 100) {
            percentage = Optional.of(100f);
        }
    }

    return percentage;
}

From source file:org.cowboyprogrammer.org.OrgTimestamp.java

License:Open Source License

/**
 * Move this timestamp one repetition./*w  w  w  . j  av  a 2 s.  c o  m*/
 */
public void toNextRepeat() {
    if (repeater != null) {
        if (repeater.startsWith("++")) {
            final LocalDateTime now = LocalDateTime.now();
            if (now.isAfter(date)) {
                // Just get it into the future
                while (now.isAfter(date)) {
                    date = date.plus(repeatPeriod);
                }
            } else {
                // Already in future, just jump
                date = date.plus(repeatPeriod);
            }
        } else if (repeater.startsWith(".+")) {
            // Count from NOW
            date = LocalDateTime.now().plus(repeatPeriod);
        } else { // +
            date = date.plus(repeatPeriod);
        }
    }
}

From source file:org.cowboyprogrammer.org.OrgTimestamp.java

License:Open Source License

/**
 * Return the next repetition of this time, even if
 * it is already in the future. Null if no repeat.
 *///from  w w w .  j  a v  a 2s  .c om
public LocalDateTime getNextRepetition() {
    if (repeater == null)
        return null;

    final LocalDateTime now = LocalDateTime.now();
    LocalDateTime next = date.withDayOfMonth(date.getDayOfMonth());

    if (repeater.startsWith("++")) {
        if (now.isAfter(next)) {
            // Just get it into the future
            while (now.isAfter(next)) {
                next = next.plus(repeatPeriod);
            }
        } else {
            // Already in future, just jump
            next = next.plus(repeatPeriod);
        }
    } else if (repeater.startsWith(".+")) {
        // Count from NOW
        next = now.plus(repeatPeriod);
    } else { // + or
        next = next.plus(repeatPeriod);
    }

    return next;
}

From source file:org.cowboyprogrammer.org.OrgTimestamp.java

License:Open Source License

/**
 * Returns null if no repeater is set. Otherwise the next repetition of this
 * time which is in the future. If it is already in the future, it will
 * return that.//from  ww w .j ava 2s .c  o m
 */
public LocalDateTime getNextFutureRepetition() {
    if (repeater == null) {
        return null;
    }
    final LocalDateTime now = LocalDateTime.now();
    if (now.isBefore(date)) {
        // Already in future
        return date;
    }
    // In this case, + and ++ have the same behaviour
    if (repeater.startsWith("+")) {
        LocalDateTime next = date.plus(repeatPeriod);
        // Just get it into the future
        while (now.isAfter(next)) {
            next = next.plus(repeatPeriod);
        }
        return next;
    } else {
        // Count from NOW
        return now.plus(repeatPeriod);
    }
}

From source file:org.devgateway.eudevfin.exchange.dao.HistoricalExchangeRateDaoImplEndpoint.java

License:Open Source License

/**
 * @see HistoricalExchangeRateService#fetchRatesForDate(LocalDateTime)
 * @param date/* w  w w  . j  a v a 2s  .  c  om*/
 * @return
 */
@ServiceActivator(inputChannel = "fetchRatesForDateChannel")
public int fetchRatesForDate(LocalDateTime date) {
    int savedRates = 0;

    // rates exist already for the given date, currently we skip any more
    // rates fetching.
    // we can parameterize this l8r
    if (service.findRatesForDate(date).iterator().hasNext()) {
        return savedRates;
    }

    // fetch the open exchange properties
    ExchangeRateConfiguration exchangeRateBaseURL = exchangeRateConfigurationService
            .findByEntityKey(ExchangeRateConfigurationConstants.OPEN_EXCHANGE_BASE_URL).getEntity();
    ExchangeRateConfiguration exchangeRateKey = exchangeRateConfigurationService
            .findByEntityKey(ExchangeRateConfigurationConstants.OPEN_EXCHANGE_KEY).getEntity();

    if (exchangeRateBaseURL == null || exchangeRateKey == null) {
        logger.warn("baseURL or key is not defined for openexchange API.");

        return savedRates;
    }

    LinkedHashMap<String, Object> mapFromJson = null;
    try {
        LocalDateTime todayDate = new LocalDateTime();
        if (todayDate.isAfter(date)) {
            mapFromJson = exchangeQueryService.getExchangeRatesForDate(date,
                    exchangeRateBaseURL.getEntitValue(), exchangeRateKey.getEntitValue());
        } else {
            // if the transaction date is in future then we need to fetch today's rates
            mapFromJson = exchangeQueryService.getExchangeRatesForDate(todayDate,
                    exchangeRateBaseURL.getEntitValue(), exchangeRateKey.getEntitValue());
        }
    } catch (Exception e) {
        logger.error("Error while fetching the rates", e);

        return savedRates;
    }

    CurrencyUnit baseUnit = CurrencyUnit.of((String) mapFromJson.get("base"));
    @SuppressWarnings("unchecked")
    LinkedHashMap<String, Number> rates = (LinkedHashMap<String, Number>) mapFromJson.get("rates");

    Iterator<String> iterator = rates.keySet().iterator();
    while (iterator.hasNext()) {
        String currency = (String) iterator.next();
        CurrencyUnit counterUnit = null;
        try {
            counterUnit = CurrencyUnit.of(currency);
        } catch (IllegalCurrencyException e) {
            logger.warn("Unkown currency " + currency + ". Will not import the exchange rate!");
            continue;
        }

        HistoricalExchangeRate her = new HistoricalExchangeRate();

        her.setDate(date);
        her.setRate(ExchangeRate.of(baseUnit, counterUnit, new BigDecimal(rates.get(currency).toString())));
        her.setSource(ExchangeRateConstants.SOURCE_INTERNET);

        service.save(her);

        savedRates++;
    }

    return savedRates;
}

From source file:org.openmastery.publisher.core.timeline.TimeBandModel.java

License:Open Source License

public boolean contains(LocalDateTime position) {
    return (position.isAfter(getStart()) && position.isBefore(getEnd())) || position.isEqual(getStart())
            || position.isEqual(getEnd());
}

From source file:todolist.ui.controllers.SettingsController.java

/**
 * isWithinWeek/* w w  w. j  a v a2s. co  m*/
 * 
 * @param startOfWeek
 * @param endOfWeek
 * @param endTime
 * @return boolean
 */
private boolean isWithinWeek(LocalDateTime startOfWeek, LocalDateTime endOfWeek,
        java.time.LocalDateTime endTime) {

    int millis = 0;
    int seconds = endTime.getSecond();
    int minutes = endTime.getMinute();
    int hours = endTime.getHour();
    int day = endTime.getDayOfMonth();
    int month = endTime.getMonthValue();
    int year = endTime.getYear();

    LocalDateTime endTimeFormatted = new LocalDateTime();
    endTimeFormatted = endTimeFormatted.withDate(year, month, day);
    endTimeFormatted = endTimeFormatted.withTime(hours, minutes, seconds, millis);

    return endTimeFormatted.isAfter(startOfWeek) && endTimeFormatted.isBefore(endOfWeek);
}

From source file:view.schema.ShiftTile.java

private Paint getColorOnShiftStart(LocalDateTime shiftTime) {
    //hours//www.  jav  a 2 s.c  om
    LocalDateTime tempShiftEveningStart = shiftTime.withField(DateTimeFieldType.hourOfDay(),
            ShiftPeriodConstants.EVENING_SHIFT_HOURS_START.getHours());
    LocalDateTime tempShiftNightStart = shiftTime.withField(DateTimeFieldType.hourOfDay(),
            ShiftPeriodConstants.NIGHT_SHIFT_HOURS_START.getHours());
    LocalDateTime tempShiftDayStart = shiftTime.withField(DateTimeFieldType.hourOfDay(),
            ShiftPeriodConstants.DAY_SHIFT_HOURS_START.getHours());
    //Minutes.
    tempShiftEveningStart = tempShiftEveningStart.withField(DateTimeFieldType.minuteOfHour(),
            ShiftPeriodConstants.EVENING_SHIFT_MINUTES_START.getMinutes());
    tempShiftNightStart = tempShiftNightStart.withField(DateTimeFieldType.minuteOfHour(),
            ShiftPeriodConstants.NIGHT_SHIFT_MINUTES_START.getMinutes());
    tempShiftDayStart = tempShiftDayStart.withField(DateTimeFieldType.minuteOfHour(),
            ShiftPeriodConstants.DAY_SHIFT_MINUTES_START.getMinutes());

    if (shiftTime.isEqual(tempShiftDayStart)
            || (shiftTime.isBefore(tempShiftEveningStart) && shiftTime.isAfter(tempShiftDayStart))) {
        return BLUE;
    } else if (shiftTime.isEqual(tempShiftEveningStart)
            || (shiftTime.isBefore(tempShiftNightStart) && shiftTime.isAfter(tempShiftEveningStart))) {
        return GREEN;
    } else {
        return RED;
    }
}