Java Code Examples for org.joda.time.LocalDate#isBefore()

The following examples show how to use org.joda.time.LocalDate#isBefore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalendarUtils.java    From estatio with Apache License 2.0 6 votes vote down vote up
public static List<Interval> intervalsInRange(
        final LocalDate startDate,
        final LocalDate endDate,
        final String rrule) {
    if (startDate.compareTo(endDate) > 0) {
        throw new IllegalArgumentException(
                String.format("Start date %s is after end date %s", startDate.toString(), endDate.toString()));
    }
    List<Interval> intervals = Lists.newArrayList();
    LocalDate start = startDate;
    Interval interval = null;
    do {
        interval = intervalContaining(start, rrule);
        if (interval != null) {
            intervals.add(interval);
            start = interval.getEnd().toLocalDate();
        }
    } while (interval != null && start.isBefore(endDate));
    return intervals;
}
 
Example 2
Source File: BiWeekIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;
    int quantity = checkDate.weekOfWeekyear().getMaximumValue()/2;
    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(2))) && counter < quantity) {
        String year = checkDate.year().getAsString();
        String cDate = checkDate.toString();
        String nDate = checkDate.plusWeeks(2).minusDays(1).toString();

        String date = String.format(DATE_FORMAT, year, periodApi, counter+1);
        String label = String.format(DATE_LABEL_FORMAT, periodHumanReedable, counter+1, cDate, nDate);

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusWeeks(2);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 3
Source File: BaseCalendar.java    From NCalendar with Apache License 2.0 5 votes vote down vote up
private LocalDate getAvailableDate(LocalDate localDate) {
    if (localDate.isBefore(mStartDate)) {
        return mStartDate;
    } else if (localDate.isAfter(mEndDate)) {
        return mEndDate;
    } else {
        return localDate;
    }
}
 
Example 4
Source File: BiWeeklyExpiryDateValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int getExpiryDays(int expiryDay){
    LocalDate periodDate = new LocalDate();
    LocalDate periodInitRange = new LocalDate();
    periodInitRange = periodInitRange.withWeekOfWeekyear(1);
    do{
        periodInitRange = periodInitRange.plusWeeks(2).withDayOfWeek(DateTimeConstants.MONDAY);
    } while (periodInitRange.isBefore(periodDate));
    periodInitRange = periodInitRange.minusWeeks(2);
    return Days.daysBetween(periodInitRange.minusDays(1), new LocalDate()).getDays() + expiryDay;
}
 
Example 5
Source File: InvoiceItem.java    From estatio with Apache License 2.0 5 votes vote down vote up
public String validateChangeEffectiveDates(
        final LocalDate effectiveStartDate,
        final LocalDate effectiveEndDate){
    if (effectiveStartDate!=null && effectiveEndDate!=null && effectiveEndDate.isBefore(effectiveStartDate)){
        return "The end date is before the start date";
    }
    return null;
}
 
Example 6
Source File: Lease.java    From estatio with Apache License 2.0 5 votes vote down vote up
public String validateTerminate(
        final LocalDate terminationDate) {
    if (terminationDate.isBefore(getStartDate())) {
        return "Termination date can't be before start date";
    }
    return null;
}
 
Example 7
Source File: TurnoverAggregationService.java    From estatio with Apache License 2.0 5 votes vote down vote up
public void aggregateTurnoversForLease(final Lease lease, final LocalDate startDate, final LocalDate endDate, final boolean maintainOnly){
    //since we analyze all previous and next leases with all associated configs, any config with type prelimninary and frequency monthly will do
    TurnoverReportingConfig firstConfigCandidate = null;
    for (Occupancy o : lease.getOccupancies()){
        final TurnoverReportingConfig c = turnoverReportingConfigRepository
                .findByOccupancyAndTypeAndFrequency(o, Type.PRELIMINARY, Frequency.MONTHLY).stream().findFirst()
                .orElse(null);
        if (c!=null && firstConfigCandidate==null ){
            firstConfigCandidate = c;
        }
    }

    if (firstConfigCandidate==null) return;

    LocalDate startDateToUse = startDate==null || startDate.isBefore(MIN_AGGREGATION_DATE) ? MIN_AGGREGATION_DATE.minusMonths(23).withDayOfMonth(1) : startDate.withDayOfMonth(1);
    LocalDate endDateToUse = endDate==null ? clockService.now().withDayOfMonth(1).plusMonths(23) : endDate.withDayOfMonth(1);

    if (endDateToUse.isBefore(startDateToUse)) return;

    // since we look 24 months ahead the aggregations to be made are
    List<LocalDate> turnoverDates = new ArrayList<>();
    turnoverDates.add(startDateToUse.withDayOfMonth(1));
    LocalDate d = startDateToUse.plusMonths(24);
    while (!d.isAfter(endDateToUse)){
        turnoverDates.add(d.withDayOfMonth(1));
        d = d.plusMonths(24);
    }

    if (turnoverDates.isEmpty()) return;

    if (maintainOnly){
        aggregate(turnoverDates.get(0), firstConfigCandidate, null, true);
    } else {
        for (LocalDate toDate : turnoverDates) {
            aggregate(toDate, firstConfigCandidate, null, maintainOnly);
        }
    }

}
 
Example 8
Source File: SixMonthIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;


    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(6))) && counter < 2) {
        String year = checkDate.year().getAsString();
        String label;
        String date;

        if (checkDate.getMonthOfYear() > JUN) {
            label = String.format(DATE_LABEL_FORMAT, JUL_STR_LONG, DEC_STR_LONG, year);
            date = year + S2;
        } else {
            label = String.format(DATE_LABEL_FORMAT, JAN_STR_LONG, JUN_STR_LONG, year);
            date = year + S1;
        }

        checkDate = checkDate.plusMonths(6);
        counter++;

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 9
Source File: WeekSaturdayIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;
    int quantity = checkDate.weekOfWeekyear().getMaximumValue();
    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(1).minusDays(1))) && counter < quantity) {
        String year = checkDate.year().getAsString();
        String cWeekNumber = "" + (Integer.parseInt(checkDate.weekOfWeekyear().getAsString())+ 1 );
        String cDate = checkDate.toString();
        String nDate = checkDate.plusWeeks(1).minusDays(1).toString();

        String date = String.format(DATE_FORMAT, year, W, cWeekNumber);
        String label = String.format(DATE_LABEL_FORMAT, W, cWeekNumber, cDate, nDate);

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusWeeks(1);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 10
Source File: WeekSundayIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;
    int quantity = checkDate.weekOfWeekyear().getMaximumValue();
    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(1).minusDays(1))) && counter < quantity) {
        String year = checkDate.year().getAsString();
        String cWeekNumber = "" + (Integer.parseInt(checkDate.weekOfWeekyear().getAsString())+ 1 );
        String cDate = checkDate.toString();
        String nDate = checkDate.plusWeeks(1).minusDays(1).toString();

        String date = String.format(DATE_FORMAT, year, W, cWeekNumber);
        String label = String.format(DATE_LABEL_FORMAT, W, cWeekNumber, cDate, nDate);

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusWeeks(1);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 11
Source File: Occupancy_createEmptyTurnovers.java    From estatio with Apache License 2.0 5 votes vote down vote up
@Action()
public Occupancy $$(final LocalDate startDate, final LocalDate endDate) {
    if (!endDate.isBefore(startDate)){
        final List<TurnoverReportingConfig> configs = turnoverReportingConfigRepository.findByOccupancy(occupancy);
        LocalDate date = startDate;
        while (!date.isAfter(endDate)){
            for (TurnoverReportingConfig config : configs){
                config.produceEmptyTurnover(date);
            }
            date = date.plusDays(1);
        }
    }
    return occupancy;
}
 
Example 12
Source File: DayIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);

    int counter = 0;
    int quantity = checkDate.dayOfYear().getMaximumValue();

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate)) && counter < quantity) {

        String date = checkDate.toString(DATE_FORMAT);

        String dName = checkDate.dayOfMonth().getAsString();
        String mName = checkDate.monthOfYear().getAsText();
        String yName = checkDate.year().getAsString();

        String label = String.format(DATE_LABEL_FORMAT, dName, mName, yName);


        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusDays(1);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 13
Source File: Lease.java    From estatio with Apache License 2.0 5 votes vote down vote up
public String validateRenew(
        final String reference,
        final String name,
        final LocalDate startDate,
        final LocalDate endDate
) {
    if (endDate.isBefore(startDate)) {
        return "End date can not be before start date.";
    }
    return leaseRepository.findLeaseByReferenceElseNull(reference) == null ? null : "Lease reference already exists.";
}
 
Example 14
Source File: QuarterYearIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(3))) && counter < 4) {
        String label;
        String date;

        int cMonth = checkDate.getMonthOfYear();
        String cYearStr = checkDate.year().getAsString();

        if (cMonth < MAR) {
            date = cYearStr + Q1;
            label = String.format(DATE_LABEL_FORMAT, JAN_STR, MAR_STR, cYearStr);
        } else if ((cMonth >= MAR) && (cMonth < JUN)) {
            date = cYearStr + Q2;
            label = String.format(DATE_LABEL_FORMAT, APR_STR, JUN_STR, cYearStr);
        } else if ((cMonth >= JUN) && (cMonth < SEP)) {
            date = cYearStr + Q3;
            label = String.format(DATE_LABEL_FORMAT, JUL_STR, SEP_STR, cYearStr);
        } else {
            date = cYearStr + Q4;
            label = String.format(DATE_LABEL_FORMAT, OCT_STR, DEC_STR, cYearStr);
        }

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        checkDate = checkDate.plusMonths(3);
        counter++;
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 15
Source File: ConversionUtilities.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
static public LocalDate parseDate(String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }

    if (value.length() < 2) {
        return null;
    }

    LocalDate result = null;
    String normalizedValue = value;

    if (value.length() == "dMMyyyy".length()) {
        normalizedValue = "0".concat(value);
    }

    for (String pattern : CORRECT_DATE_PATTERNS) {
        try {
            result = DateTimeFormat.forPattern(pattern).parseDateTime(normalizedValue).toLocalDate();
        } catch (IllegalArgumentException e) {
            continue;
        }

        if (result.isAfter(DateTimeFormat.forPattern("yyyy").parseDateTime("1920").toLocalDate())
                && result.isBefore(DateTimeFormat.forPattern("yyy").parseDateTime("2020").toLocalDate())) {
            return result;
        }
    }

    throw new IncorrectDateFormatException(value);
}
 
Example 16
Source File: IncomingInvoiceDownloadManager.java    From estatio with Apache License 2.0 4 votes vote down vote up
public String validateDownloadToExcelForAllProperties(final LocalDate startDate, final LocalDate endDate, final Country country, final String fileName) {
    if (endDate.isBefore(startDate))
        return "End date cannot be before start date";
    return null;
}
 
Example 17
Source File: BiMonthIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    int counter = 0;
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(2))) && counter < 6) {
        int cMonth = checkDate.getMonthOfYear();
        String year = checkDate.year().getAsString();

        String date;
        String label;

        if (cMonth < FEB) {
            date = year + B1;
            label = String.format(DATE_LABEL_FORMAT, JAN_STR, FEB_STR, year);
        } else if ((cMonth >= FEB) && (cMonth < APR)) {
            date = year + B2;
            label = String.format(DATE_LABEL_FORMAT, MAR_STR, APR_STR, year);
        } else if ((cMonth >= APR) && (cMonth < JUN)) {
            date = year + B3;
            label = String.format(DATE_LABEL_FORMAT, MAY_STR, JUN_STR, year);
        } else if ((cMonth >= JUN) && (cMonth < AUG)) {
            date = year + B4;
            label = String.format(DATE_LABEL_FORMAT, JUL_STR, AUG_STR, year);
        } else if ((cMonth >= AUG) && (cMonth < OCT)) {
            date = year + B5;
            label = String.format(DATE_LABEL_FORMAT, SEP_STR, OCT_STR, year);
        } else {
            date = year + B6;
            label = String.format(DATE_LABEL_FORMAT, NOV_STR, DEC_STR, year);
        }


        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusMonths(2);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 18
Source File: Lease_aggregateTurnovers.java    From estatio with Apache License 2.0 4 votes vote down vote up
public String validate$$(final LocalDate startDate, final LocalDate endDate, final boolean maintainOnly){
    if (startDate!=null && endDate!=null){
        if (endDate.isBefore(startDate)) return "The end date cannot be before the start date";
    }
    return null;
}
 
Example 19
Source File: Project.java    From estatio with Apache License 2.0 4 votes vote down vote up
private String validateNewProject(final String reference, final LocalDate startDate, final LocalDate endDate) {
    if (projectRepository.findByReference(reference) != null)
        return "There is already a project with this reference";
    return startDate != null && endDate != null && !startDate.isBefore(endDate) ? "End date must be after start date" : null;
}
 
Example 20
Source File: LegionBoardParser.java    From substitution-schedule-parser with Mozilla Public License 2.0 4 votes vote down vote up
void parseLegionBoard(SubstitutionSchedule substitutionSchedule, JSONArray changes, JSONArray courses,
                         JSONArray teachers) throws IOException, JSONException {
       if (changes == null) {
		return;
	}
	// Link course IDs to their names
	HashMap<String, String> coursesHashMap = null;
	if (courses != null) {
		coursesHashMap = new HashMap<>();
		for (int i = 0; i < courses.length(); i++) {
			JSONObject course = courses.getJSONObject(i);
			coursesHashMap.put(course.getString("id"), course.getString("name"));
		}
	}
	// Link teacher IDs to their names
	HashMap<String, String> teachersHashMap = null;
	if (teachers != null) {
		teachersHashMap = new HashMap<>();
		for (int i = 0; i < teachers.length(); i++) {
			JSONObject teacher = teachers.getJSONObject(i);
			teachersHashMap.put(teacher.getString("id"), teacher.getString("name"));
		}
	}
	// Add changes to SubstitutionSchedule
	LocalDate currentDate = LocalDate.now();
	SubstitutionScheduleDay substitutionScheduleDay = new SubstitutionScheduleDay();
	substitutionScheduleDay.setDate(currentDate);
	for (int i = 0; i < changes.length(); i++) {
		final JSONObject change = changes.getJSONObject(i);
		final Substitution substitution = getSubstitution(change, coursesHashMap, teachersHashMap);
		final LocalDate startingDate = new LocalDate(change.getString("startingDate"));
		final LocalDate endingDate = new LocalDate(change.getString("endingDate"));
		// Handle multi-day changes
		if (!startingDate.isEqual(endingDate)) {
			if (!substitutionScheduleDay.getSubstitutions().isEmpty()) {
				substitutionSchedule.addDay(substitutionScheduleDay);
			}
			for (int k = 0; k < 8; k++) {
				final LocalDate date = LocalDate.now().plusDays(k);
				if ((date.isAfter(startingDate) || date.isEqual(startingDate)) &&
					(date.isBefore(endingDate) || date.isEqual(endingDate))) {
					substitutionScheduleDay = new SubstitutionScheduleDay();
					substitutionScheduleDay.setDate(date);
					substitutionScheduleDay.addSubstitution(substitution);
					substitutionSchedule.addDay(substitutionScheduleDay);
                       currentDate = date;
                   }
			}
			continue;
		}
		// If starting date of change does not equal date of SubstitutionScheduleDay
		if (!startingDate.isEqual(currentDate)) {
			if (!substitutionScheduleDay.getSubstitutions().isEmpty()) {
				substitutionSchedule.addDay(substitutionScheduleDay);
			}
			substitutionScheduleDay = new SubstitutionScheduleDay();
			substitutionScheduleDay.setDate(startingDate);
               currentDate = startingDate;
           }
		substitutionScheduleDay.addSubstitution(substitution);
	}
	substitutionSchedule.addDay(substitutionScheduleDay);
}