Example usage for org.joda.time LocalDate equals

List of usage examples for org.joda.time LocalDate equals

Introduction

In this page you can find the example usage for org.joda.time LocalDate equals.

Prototype

public boolean equals(Object partial) 

Source Link

Document

Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.

Usage

From source file:com.stagecents.hxt.domain.Timecard.java

License:Open Source License

public int getSummaryHoursSequence(LocalDate dateWorked) {
    int seq = 0;/*from  w w w  .  j  a v a 2  s.  c  o m*/
    Iterator<SummaryHours> iter = summaryHours.iterator();
    while (iter.hasNext()) {
        SummaryHours sh = iter.next();
        if (sh.getDateWorked().equals(dateWorked)) {
            return sh.getSequence();
        }
        LocalDate tmp = getStartDate().plusDays(seq);
        if (tmp.equals(dateWorked)) {
            return seq;
        }
        seq++;
    }
    return seq;
}

From source file:com.the.todo.Logic.java

License:MIT License

private void sortByDate(Map<DateCategory, List<ToDo>> todoMap, List<ToDo> todoList) {
    todoMap.clear();//ww  w .j  ava2 s .co m

    Type todoType;
    LocalDate startDate;
    LocalDate endDate;
    LocalDate today = new LocalDate();
    LocalDate tomorrow = new LocalDate().plusDays(1);

    List<ToDo> todoOverdue = new ArrayList<ToDo>();
    List<ToDo> todoToday = new ArrayList<ToDo>();
    List<ToDo> todoTomorrow = new ArrayList<ToDo>();
    List<ToDo> todoUpcoming = new ArrayList<ToDo>();
    List<ToDo> todoSomeday = new ArrayList<ToDo>();

    for (ToDo todo : todoList) {
        todoType = todo.getType();
        startDate = todo.getStartDate().toLocalDate();
        endDate = todo.getEndDate().toLocalDate();

        if (todoType == Type.FLOATING) {
            todoSomeday.add(todo);
        }

        if (todoType == Type.DEADLINE) {
            if (endDate.isBefore(today)) {
                todoOverdue.add(todo);
            } else if (endDate.equals(today)) {
                todoToday.add(todo);
            } else if (endDate.equals(tomorrow)) {
                todoTomorrow.add(todo);
            }
        }

        if (todoType == Type.TIMED) {
            if (endDate.isBefore(today)) {
                todoOverdue.add(todo);
            }
            if (!today.isBefore(startDate) && !today.isAfter(endDate)) {
                todoToday.add(todo);
            }
            if (!tomorrow.isBefore(startDate) && !tomorrow.isAfter(endDate)) {
                todoTomorrow.add(todo);
            }
        }

        if (displayType == DisplayType.SEARCH) {
            if (todoType == Type.DEADLINE) {
                if (endDate.isAfter(tomorrow)) {
                    todoUpcoming.add(todo);
                }
            } else if (todoType == Type.TIMED) {
                if (endDate.isAfter(tomorrow)) {
                    todoUpcoming.add(todo);
                }
            }
        }
    }

    if (todoOverdue.size() > 0) {
        todoMap.put(DateCategory.OVERDUE, todoOverdue);
    }
    if (todoToday.size() > 0) {
        todoMap.put(DateCategory.TODAY, todoToday);
    }
    if (todoTomorrow.size() > 0) {
        todoMap.put(DateCategory.TOMORROW, todoTomorrow);
    }
    if (todoUpcoming.size() > 0) {
        todoMap.put(DateCategory.UPCOMING, todoUpcoming);
    }
    if (todoSomeday.size() > 0) {
        todoMap.put(DateCategory.SOMEDAY, todoSomeday);
    }

    for (Entry<DateCategory, List<ToDo>> entry : todoMap.entrySet()) {
        Collections.sort(entry.getValue());
    }
}

From source file:courtscheduler.domain.DateConstraint.java

License:Apache License

public Integer[] findDayOfWeek(int weekday) {
    LocalDate firstDay = info.getConferenceStartDate().withDayOfWeek(weekday);
    ArrayList<Integer> days = new ArrayList<Integer>();
    if (firstDay.isBefore(info.getConferenceStartDate())) {
        firstDay.plusWeeks(1);//  ww  w  .ja  va  2s .c  o  m
    }
    while (firstDay.isBefore(info.getConferenceEndDate()) || firstDay.equals(info.getConferenceEndDate())) {
        Integer index = Days.daysBetween(info.getConferenceStartDate(), firstDay).getDays();
        if (index >= 0) {
            days.add(index);
        }
        firstDay = firstDay.plusWeeks(1);
    }
    return days.toArray(new Integer[days.size()]);
}

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"));
    }/*from  ww  w  .jav a2 s  .co  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:edu.harvard.med.iccbl.screensaver.service.screens.ScreenDataSharingLevelUpdater.java

License:Open Source License

/**
 * For Screens that:/*w ww . j a va 2  s  .c o  m*/
 * <ul>
 * <li>have ScreenResults
 * <li>have ScreenDataSharingLevel that is more restrictive than {@link ScreenDataSharingLevel#MUTUAL_SCREENS}
 * <li>have a {@link Screen#getDataPrivacyExpirationDate()} on or before the expireDate
 * <li>do not have a status of {@link ScreenStatus#DROPPED_TECHNICAL} or {@link ScreenStatus#TRANSFERRED_TO_BROAD_INSTITUTE}
 * </ul>
 * This method invokes {@link Screen#setDataPrivacyExpirationDate(LocalDate)} with a value that is ageToExpireFromActivityDateInDays
 * days from the latest LabActivity (by date) for the Screen.  
 * @param ageToExpireFromActivityDateInDays the expiration period, in days
 * @param admin user performing
 * @return List<Screen, Pair<Admin-activity-if-any, message-if-no-action> >
 */
@Transactional
public DataPrivacyAdjustment adjustDataPrivacyExpirationByActivities(int ageToExpireFromActivityDateInDays,
        AdministratorUser admin, ScreenType screenType) {
    admin = _dao.reloadEntity(admin);
    String hql = "select distinct(s) from Screen as s " + " join s.screenResult sr "
            + " inner join s.labActivities la " + " where " + " s.screenType = ? "
            + " and s.dataSharingLevel > ? "
            + " and s.screenId not in (select s2.screenId from Screen s2 join s2.statusItems si where si.status in ( ?, ? ) and s2=s ) "
            + " order by s.screenId";

    List<Screen> screens = _dao.findEntitiesByHql(Screen.class, hql, screenType,
            ScreenDataSharingLevel.MUTUAL_SCREENS, ScreenStatus.DROPPED_TECHNICAL,
            ScreenStatus.TRANSFERRED_TO_BROAD_INSTITUTE);

    // Note, have to iterate in code to examine the date values as a suitable date arithmetic method was not determined for the HQL - sde4

    DataPrivacyAdjustment dataPrivacyAdjustment = new DataPrivacyAdjustment();

    for (Screen s : screens) {
        // note that getLabActivities does a "natural" sort, and that the comparator for the LabActivity uses the dateOfActivity to sort.

        SortedSet<LibraryScreening> libraryScreenings = s.getLabActivitiesOfType(LibraryScreening.class);
        if (libraryScreenings.isEmpty()) {
            log.debug("No LibraryScreenings for the screen: " + s);
        } else {
            //for [#2285] - don't consider Library Screenings of user provided plates 
            for (Iterator<LibraryScreening> iter = libraryScreenings.iterator(); iter.hasNext();) {
                if (iter.next().isForExternalLibraryPlates())
                    iter.remove();
            }
            LibraryScreening libraryScreening = libraryScreenings.last();

            LocalDate requestedDate = libraryScreening.getDateOfActivity()
                    .plusDays(ageToExpireFromActivityDateInDays);
            LocalDate currentExpiration = s.getDataPrivacyExpirationDate();

            if (currentExpiration != null && currentExpiration.equals(requestedDate)) {
                log.info("DataPrivacyExpirationDate is already set to the correct value for screen number: "
                        + s.getFacilityId());
            } else {
                s.setDataPrivacyExpirationDate(requestedDate);
                LocalDate setDate = s.getDataPrivacyExpirationDate();

                AdministrativeActivity adminActivity = null;

                if (currentExpiration != null && currentExpiration.equals(setDate)) {
                    // adjustment not allowed - overridden
                    String msg = _messages.getMessage(
                            "admin.screens.dataPrivacyExpiration.dataPrivacyExpirationdate.adjustment.adjustmentNotAllowed.comment",
                            currentExpiration, libraryScreening.getDateOfActivity(), requestedDate);

                    dataPrivacyAdjustment.screenPrivacyAdjustmentNotAllowed.add(Pair.newPair(s, msg));
                } else {
                    if (!requestedDate.equals(setDate)) {
                        // adjustment allowed - but overridden to...
                        String msg = _messages.getMessage(
                                "admin.screens.dataPrivacyExpiration.dataPrivacyExpirationdate.adjustment.adjustedBasedOnAllowed.comment",
                                currentExpiration, libraryScreening.getDateOfActivity(), requestedDate,
                                setDate);
                        adminActivity = s.createUpdateActivity(admin, msg);
                        dataPrivacyAdjustment.screensAdjustedToAllowed.add(Pair.newPair(s, adminActivity));
                    } else {
                        // adjustment allowed
                        String msg = _messages.getMessage(
                                "admin.screens.dataPrivacyExpiration.dataPrivacyExpirationdate.adjustment.basedOnActivity.comment",
                                currentExpiration, libraryScreening.getDateOfActivity(), setDate);
                        adminActivity = s.createUpdateActivity(admin, msg);
                        dataPrivacyAdjustment.screensAdjusted.add(Pair.newPair(s, adminActivity));
                    }
                    // we null the notified date, since it should be re-notified -sde4
                    s.setDataPrivacyExpirationNotifiedDate(null);
                }
            }
        }
    }
    log.info("adjustDataPrivacyExpirationByActivities, " + " adjusted: "
            + dataPrivacyAdjustment.screensAdjusted.size() + " adjusted to allowed: "
            + dataPrivacyAdjustment.screensAdjustedToAllowed.size() + ", adjustment not allowed: "
            + dataPrivacyAdjustment.screenPrivacyAdjustmentNotAllowed.size());
    return dataPrivacyAdjustment;
}

From source file:edu.harvard.med.screensaver.db.usertypes.LocalDateType.java

License:Open Source License

public boolean equals(Object x, Object y) throws HibernateException {
    if (x == y) {
        return true;
    }/*  w  w w .  j a va  2  s . co m*/
    if (x == null || y == null) {
        return false;
    }
    LocalDate dtx = (LocalDate) x;
    LocalDate dty = (LocalDate) y;

    return dtx.equals(dty);
}

From source file:energy.usef.agr.workflow.operate.identifychangeforecast.AgrIdentifyChangeInForecastCoordinator.java

License:Apache License

private void triggerNextSteps(LocalDate period, List<PtuContainerDto> changedPtus) {
    final LocalDate today = DateTimeUtil.getCurrentDate();
    if (today.isEqual(period)) {
        List<PtuContainerDto> changedPtusForToday = changedPtus.stream()
                .filter(changedPtu -> today.equals(changedPtu.getPtuDate())).collect(Collectors.toList());
        triggerNextStepsForToday(today, changedPtusForToday);
    } else if (changedPtus.stream().map(PtuContainerDto::getPtuDate).distinct().anyMatch(period::isEqual)) {
        reOptimizePortfolioEventManager.fire(new ReOptimizePortfolioEvent(period));
    }//from  www .jav  a2  s . c o  m
}

From source file:energy.usef.core.repository.PtuContainerRepository.java

License:Apache License

/**
 * Apply a bulk update to the PtuContainer entities.
 *
 * @param phase {@link PhaseType} new PhaseType of the {@link PtuContainer}.
 * @param period {@link LocalDate} date of the {@link PtuContainer} that will be changed.
 * @param ptuIndex {@link Integer}. Optional filter to limit the update to a specific PTU index.
 * @return the number of records updated.
 *//* ww  w  . j  ava  2s. co  m*/
@Transactional(Transactional.TxType.REQUIRES_NEW)
public int updatePtuContainersPhase(PhaseType phase, LocalDate period, Integer ptuIndex) {
    boolean isPlanValidate = PhaseType.Plan.equals(phase) || PhaseType.Validate.equals(phase);

    StringBuilder sql = new StringBuilder();
    sql.append("UPDATE PtuContainer ");
    sql.append("SET phase = :phase ");
    sql.append("WHERE ptuDate = :period ");
    if (isPlanValidate && period.equals(DateTimeUtil.getCurrentDate())) {
        // only future ptus may be updated.
        sql.append(" AND ptuIndex > :currentPtu ");
    }
    if (ptuIndex != null) {
        sql.append(" AND ptuIndex = :ptuIndex ");
    }

    Query query = getEntityManager().createQuery(sql.toString()).setParameter("phase", phase)
            .setParameter("period", period.toDateMidnight().toDate());

    if (isPlanValidate && period.equals(DateTimeUtil.getCurrentDate())) {
        // only future ptus may be updated.
        int currentPtuIndex = PtuUtil.getPtuIndex(
                DateTimeUtil.getCurrentDateTime().plusSeconds(PTU_OFFSET_IN_SECONDS),
                config.getIntegerProperty(ConfigParam.PTU_DURATION));
        query = query.setParameter("currentPtu", currentPtuIndex);
    }
    if (ptuIndex != null) {
        query = query.setParameter("ptuIndex", ptuIndex);
    }
    return query.executeUpdate();
}

From source file:es.usc.citius.servando.calendula.DailyAgendaRecyclerAdapter.java

License:Open Source License

public void onBindEmptyItemViewHolder(EmptyItemViewHolder viewHolder, DailyAgendaItemStub item, int position) {
    viewHolder.stub = item;/*  w ww .  ja  v  a 2s  . c  o  m*/

    if (expanded) {
        LocalDate d = viewHolder.stub.date;
        if (d.equals(DateTime.now().toLocalDate())) {
            viewHolder.hourText.setText(item.time != null ? item.time.toString("kk:mm") : "--");
        } else {
            viewHolder.hourText.setText(item.dateTime().toString("kk:mm"));
        }
    }
    viewHolder.itemView.setVisibility(expanded ? View.VISIBLE : View.GONE);

    ViewGroup.LayoutParams params = viewHolder.container.getLayoutParams();
    int newHeight = expanded ? emptyItemHeight : 0;
    if (params.height != newHeight) {
        params.height = newHeight;
        viewHolder.container.setLayoutParams(params);
    }
}

From source file:graphene.util.time.JodaTimeUtil.java

License:Apache License

public static void test_localDate() {
    System.out.println("Test LocalDate");
    final LocalDate ld1 = new LocalDate();
    final java.sql.Date d = toSQLDate(ld1);
    final LocalDate ld2 = toLocalDate(d);
    System.out.println("LocalDate 1 = " + ld1);
    System.out.println("Date        = " + d);
    System.out.println("LocalDate 2 = " + ld2);
    if (!ld2.equals(ld1)) {
        throw new IllegalStateException();
    }//  ww  w . j  av  a  2  s. c o  m
}