Example usage for org.joda.time LocalTime compareTo

List of usage examples for org.joda.time LocalTime compareTo

Introduction

In this page you can find the example usage for org.joda.time LocalTime compareTo.

Prototype

public int compareTo(ReadablePartial partial) 

Source Link

Document

Compares this partial with another returning an integer indicating the order.

Usage

From source file:com.jgoetsch.eventtrader.filter.TimeOfDayFilter.java

License:Apache License

public TimeOfDayFilter(LocalTime startTime, LocalTime endTime, DateTimeZone timeZone) {
    if (startTime.compareTo(endTime) > 1)
        throw new IllegalArgumentException("startTime cannot be after endTime");
    this.startTime = startTime;
    this.endTime = endTime;
    this.timeZone = timeZone;
}

From source file:com.jgoetsch.eventtrader.filter.TimeOfDayFilter.java

License:Apache License

@Override
protected boolean handleProcessing(Msg msg, Map<Object, Object> context) {
    LocalTime msgTime = new LocalTime(msg.getDate(), timeZone);
    return msgTime.compareTo(startTime) > 0 && msgTime.compareTo(endTime) < 0;
}

From source file:com.jgoetsch.tradeframework.marketdata.HistoricalMarketDataFeed.java

License:Apache License

/**
 * Overridable method to adjust a timestamp to the next regular trading session
 * of the given contract if it falls outside of the contract's regular trading hours.
 * /*from   ww w .  j  a v a 2s .c o  m*/
 * @param timestamp
 * @param contract
 * @return millisecond timestamp adjusted up to a regular trading session.
 */
protected long adjustTimestampToRTH(long timestamp, Contract contract) {
    if ("STK".equals(contract.getType()) && "USD".equals(contract.getCurrency())) {
        DateTime dt = new DateTime(timestamp, DateTimeZone.forID("America/New_York"));
        LocalTime time = new LocalTime(dt);
        if (time.compareTo(new LocalTime(9, 30)) < 0)
            dt = dt.withHourOfDay(9).withMinuteOfHour(30);
        else if (time.compareTo(new LocalTime(16, 0)) >= 0) {
            dt = dt.plusDays(1).withHourOfDay(9).withMinuteOfHour(30);
        }
        if (dt.getDayOfWeek() == DateTimeConstants.SATURDAY)
            dt = dt.plusDays(2);
        else if (dt.getDayOfWeek() == DateTimeConstants.SUNDAY)
            dt = dt.plusDays(1);
        return dt.getMillis();
    } else if ("FUT".equals(contract.getType()) && "USD".equals(contract.getCurrency())) {
        DateTime dt = new DateTime(timestamp, DateTimeZone.forID("America/Chicago"));
        if (dt.getDayOfWeek() == DateTimeConstants.SATURDAY)
            dt = dt.plusDays(2).withHourOfDay(9).withMinuteOfHour(0);
        else if (dt.getDayOfWeek() == DateTimeConstants.SUNDAY)
            dt = dt.plusDays(1).withHourOfDay(9).withMinuteOfHour(0);
        return dt.getMillis();
    } else
        return timestamp;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

/**
 * <code>null</code> safe compare.<br>
 * Note: it has the same semantics as//from  w ww .  ja  v a 2 s . c o  m
 * {@link com.phloc.commons.compare.CompareUtils#nullSafeCompare(Comparable, Comparable)}
 * except that the parameter class does not implement
 * {@link java.lang.Comparable} in a Generics-way!
 *
 * @param aTime1
 *        First object. May be <code>null</code>.
 * @param aTime2
 *        Second object. May be <code>null</code>.
 * @return -1, 0 or +1
 */
public static int nullSafeCompare(@Nullable final LocalTime aTime1, @Nullable final LocalTime aTime2) {
    return aTime1 == aTime2 ? 0 : aTime1 == null ? -1 : aTime2 == null ? +1 : aTime1.compareTo(aTime2);
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isGreater(@Nonnull final LocalTime aTime1, @Nonnull final LocalTime aTime2) {
    return aTime1.compareTo(aTime2) > 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isGreaterOrEqual(@Nonnull final LocalTime aTime1, @Nonnull final LocalTime aTime2) {
    return aTime1.compareTo(aTime2) >= 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isLess(@Nonnull final LocalTime aTime1, @Nonnull final LocalTime aTime2) {
    return aTime1.compareTo(aTime2) < 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isLessOrEqual(@Nonnull final LocalTime aTime1, @Nonnull final LocalTime aTime2) {
    return aTime1.compareTo(aTime2) <= 0;
}

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

private void validateAndAddObjectsToView(ModelAndView mav, HttpServletRequest request, Booking booking,
        String day, String time, Offer offer) throws Exception {
    LocalDate selectedDate = FormatUtils.DATE_HUMAN_READABLE.parseLocalDate(day);
    LocalTime selectedTime = FormatUtils.TIME_HUMAN_READABLE.parseLocalTime(time);

    LocalDate today = new LocalDate();
    LocalTime now = new LocalTime();
    if (selectedDate.compareTo(today) < 0 || (selectedDate.equals(today) && selectedTime.compareTo(now) < 0)) {
        throw new Exception(msg.get("RequestedTimeIsInThePast"));
    }/* w  w  w  .ja va 2  s  . c o m*/

    LocalDate lastDay = bookingUtil.getLastBookableDay(request);
    if (selectedDate.isAfter(lastDay)) {
        throw new Exception(msg.get("RequestedTimeIsInTheFuture"));
    }

    //create a list of possible booking durations taking into account calendar configurations and confirmed bookings
    List<CalendarConfig> configs = calendarConfigDAO.findFor(selectedDate);
    List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsForDate(selectedDate);
    OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice(configs, confirmedBookings,
            selectedDate, selectedTime, offer);

    //notify the user in case there are no durations bookable
    if (offerDurationPrice == null) {
        throw new Exception(msg.get("NoFreeCourtsForSelectedTimeAndDate"));
    }

    //store user provided data in the session booking
    booking.setBookingDate(selectedDate);
    booking.setBookingTime(selectedTime);

    //set currency and price if offer and duration have been selected
    if (booking.getOffer() != null && booking.getDuration() != null) {
        if (offerDurationPrice.getOffer().equals(booking.getOffer())) {
            BigDecimal price;
            switch (booking.getPaymentMethod()) {
            case Subscription:
                price = BigDecimal.ZERO;
                break;
            default:
                price = offerDurationPrice.getDurationPriceMap().get(booking.getDuration().intValue());

            }
            booking.setAmount(price);
            booking.setCurrency(offerDurationPrice.getConfig().getCurrency());
        }
    }

    sessionUtil.setBooking(request, booking);

    if (mav != null) {
        mav.addObject("Booking", booking);
        mav.addObject("OfferDurationPrice", offerDurationPrice);
        mav.addObject("SelectedOffer", offer);
    }
}

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

public void checkForBookedCourts(TimeSlot timeSlot, List<Booking> confirmedBookings,
        Boolean preventOverlapping) {
    LocalTime startTime = timeSlot.getStartTime();
    LocalTime endTime = timeSlot.getEndTime();

    for (Booking booking : confirmedBookings) {

        if (timeSlot.getDate().equals(booking.getBookingDate())) {
            LocalTime bookingStartTime = booking.getBookingTime();
            LocalTime bookingEndTime = bookingStartTime.plusMinutes(booking.getDuration().intValue());
            Boolean addBooking = false;
            if (preventOverlapping) {
                if (startTime.isBefore(bookingEndTime)) {
                    if (endTime.isAfter(bookingStartTime)) {
                        addBooking = true;
                    }/*  w w w .  j a v  a  2  s  . co  m*/
                }
            } else {
                //for displaying allocations
                if (startTime.compareTo(bookingStartTime) >= 0) {
                    if (endTime.compareTo(bookingEndTime) <= 0) {
                        addBooking = true;
                    }
                }
            }
            if (addBooking) {
                Offer offer = booking.getOffer();
                for (Offer timeSlotOffer : timeSlot.getConfig().getOffers()) {
                    if (offer.equals(timeSlotOffer)) {
                        timeSlot.addBooking(booking);
                        break;
                    }
                }
            }
        }
    }
}