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:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

protected CalendarItem[] buildDayItems() {

    LocalDate calendarFirstDay = getCalendarFirstDay();
    LocalDate calendarLastDay = getCalendarLastDay();

    LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1);
    LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue();

    LocalDate today = LocalDate.now();
    int numberOfDays = Days.daysBetween(calendarFirstDay, calendarLastDay).getDays() + 1;
    LocalDate date = calendarFirstDay;

    CalendarItem[] calendarItems = new CalendarItem[numberOfDays];
    LocalDate currentValue = getLocalDate();
    for (int i = 0; i < numberOfDays; i++, date = date.plusDays(1)) {
        calendarItems[i] = new CalendarItem();

        calendarItems[i].setIndex(i);/*  ww  w  . java 2 s. com*/
        if (date.getMonthOfYear() == yearMonthDisplayed.getMonthOfYear()) {
            calendarItems[i].setRelativeDateIndex(date.getDayOfMonth());
        } else {
            calendarItems[i].setRelativeDateIndex(-date.getDayOfMonth());
        }

        String calendarItemContent = null;
        if (cellItemCustomizer != null) {
            calendarItemContent = cellItemCustomizer.renderDay(date, this);
        }

        // fallback to default value
        if (calendarItemContent == null) {
            calendarItemContent = Integer.toString(date.getDayOfMonth());
        }
        calendarItems[i].setText(calendarItemContent);

        StringBuilder style = new StringBuilder();

        if (date.equals(today)) {
            style.append("today ");
        }

        if (currentValue != null && date.equals(currentValue)) {
            style.append("selected ");
        }

        if (date.isBefore(firstDayOfMonth)) {
            style.append("previousmonth ");
            calendarItems[i].setEnabled(!isPreviousMonthDisabled());
        } else if (date.isAfter(lastDayOfMonth)) {
            style.append("nextmonth ");
            calendarItems[i].setEnabled(!isNextMonthDisabled());
        } else {
            style.append("currentmonth ");
            calendarItems[i].setEnabled(isDateEnabled(date));
        }

        if (isWeekend(date)) {
            style.append("weekend ");
        }

        if (cellItemCustomizer != null) {
            String generatedStyle = cellItemCustomizer.getStyle(date, this);
            if (generatedStyle != null) {
                style.append(generatedStyle);
                style.append(" ");
            }

            String tooltip = cellItemCustomizer.getTooltip(date, this);
            if (tooltip != null) {
                calendarItems[i].setTooltip(tooltip);
            }
        }

        String computedStyle = style.toString();
        if (!computedStyle.isEmpty()) {
            calendarItems[i].setStyle(computedStyle);
        }
    }
    return calendarItems;
}

From source file:pt.ist.fenixedu.teacher.domain.credits.AnnualCreditsState.java

License:Open Source License

@Override
public void setFinalCalculationDate(LocalDate finalCalculationDate) {
    if (finalCalculationDate != null && !finalCalculationDate.equals(getFinalCalculationDate())
            && finalCalculationDate.isBefore(new LocalDate())) {
        throw new DomainException("renderers.validator.dateTime.beforeNow");
    }//  w w  w .  jav a2  s  . com
    if (finalCalculationDate == null || !finalCalculationDate.equals(getFinalCalculationDate())) {
        setIsFinalCreditsCalculated(false);
        super.setFinalCalculationDate(finalCalculationDate);
    }
}

From source file:pt.ist.fenixedu.teacher.domain.TeacherCredits.java

License:Open Source License

private static List<Interval> getNotOverlapedIntervals(Interval overlapInterval,
        Interval notYetOverlapedInterval) {
    List<Interval> intervals = new ArrayList<Interval>();
    LocalDate overlapIntervalStart = overlapInterval.getStart().toLocalDate();
    LocalDate overlapIntervalEnd = overlapInterval.getEnd().toLocalDate();
    LocalDate notYetOverlapedIntervalStart = notYetOverlapedInterval.getStart().toLocalDate();
    LocalDate notYetOverlapedIntervalEnd = notYetOverlapedInterval.getEnd().toLocalDate();

    if (overlapIntervalStart.equals(notYetOverlapedIntervalStart)
            && !overlapIntervalEnd.equals(notYetOverlapedIntervalEnd)) {
        intervals.add(new Interval(overlapInterval.getEnd().plusDays(1), notYetOverlapedInterval.getEnd()));

    } else if (!overlapIntervalStart.equals(notYetOverlapedIntervalStart)
            && overlapIntervalEnd.equals(notYetOverlapedIntervalEnd)) {
        intervals//from  ww  w .  ja va2  s  . c  o m
                .add(new Interval(notYetOverlapedInterval.getStart(), overlapInterval.getStart().minusDays(1)));

    } else if (!overlapIntervalStart.equals(notYetOverlapedIntervalStart)
            && !overlapIntervalEnd.equals(notYetOverlapedIntervalEnd)) {
        intervals
                .add(new Interval(notYetOverlapedInterval.getStart(), overlapInterval.getStart().minusDays(1)));
        intervals.add(new Interval(overlapInterval.getEnd().plusDays(1), notYetOverlapedInterval.getEnd()));
    }

    return intervals;
}

From source file:pt.ulisboa.tecnico.softeng.car.domain.Renting.java

/**
 * @param begin//from ww  w  .  j av a  2  s  .co  m
 * @param end
 * @return <code>true</code> if this Renting conflicts with the given date
 *         range.
 */
public boolean conflict(LocalDate begin, LocalDate end) {
    if (end.isBefore(begin)) {
        throw new CarException("Error: end date is before begin date.");
    } else if ((begin.equals(this.getBegin()) || begin.isAfter(this.getBegin()))
            && (begin.isBefore(this.getEnd()) || begin.equals(this.getEnd()))) {
        return true;
    } else if ((end.equals(this.getEnd()) || end.isBefore(this.getEnd()))
            && (end.isAfter(this.getBegin()) || end.isEqual(this.getBegin()))) {
        return true;
    } else if (begin.isBefore(this.getBegin()) && end.isAfter(this.getEnd())) {
        return true;
    }

    return false;
}