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

The following examples show how to use org.joda.time.LocalDate#plusWeeks() . 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: DateRangeStaticFacotry.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public static Collection<DateRange> splitAsDateRangeByWeek(LocalDate start, LocalDate end){
	
	Set<DateRange> dates = new LinkedHashSet<DateRange>();
	dates.add(new DateRange(start, start.withDayOfWeek(DateTimeConstants.SUNDAY)));
	
	LocalDate startDateOfWeek = start.withDayOfWeek(DateTimeConstants.MONDAY).plusWeeks(1);
	while(!startDateOfWeek.isAfter(end)){
		LocalDate endDateOfWeek = startDateOfWeek.withDayOfWeek(DateTimeConstants.SUNDAY);
		if(endDateOfWeek.isAfter(end)){
			endDateOfWeek = end;
		}
		dates.add(new DateRange(startDateOfWeek, endDateOfWeek));
		startDateOfWeek = startDateOfWeek.plusWeeks(1);
	}
	return dates;
}
 
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: BiWeeklyExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected LocalDate getMaxDateCanEdit() {
    String periodFixed = period.replace("Bi","");
    int weeks = Integer.parseInt(periodFixed.substring(periodFixed.lastIndexOf("W")+1));
    int year = Integer.parseInt(periodFixed.substring(0, periodFixed.lastIndexOf("W")));
    int count =0;
    LocalDate checkDate = new LocalDate( new LocalDate().withYear(year).withWeekOfWeekyear(1).withDayOfWeek(1));
    while(count<weeks){
        checkDate = checkDate.plusWeeks(2);
        count++;
    }
    return checkDate.minusDays(1).plusDays(expiryDays - 1);
}
 
Example 4
Source File: BiWeekIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BiWeekIterator(int openFP, String[] dataInputPeriods) {
    super(dataInputPeriods);
    openFuturePeriods = openFP;
    cPeriod = new LocalDate(currentDate.withWeekOfWeekyear(1).withDayOfWeek(1));
    checkDate = new LocalDate(cPeriod);
    maxDate = new LocalDate(currentDate.getYear(), currentDate.getMonthOfYear(), currentDate.getDayOfMonth());
    maxDate = maxDate.minusDays(currentDate.getDayOfWeek());
    if(openFuturePeriods>1) {
        for (int i = 0; i < (openFuturePeriods-1) / 2; i++) {
            maxDate = maxDate.plusWeeks(2);
        }
    }
}
 
Example 5
Source File: WeekWednesdayIterator.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 = checkDate.weekOfWeekyear().getAsString();
        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 6
Source File: WeekThursdayIterator.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 = checkDate.weekOfWeekyear().getAsString();
        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 7
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 8
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 9
Source File: WeekIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WeekIterator(int openFP, String[] dataInputPeriods) {
    super(dataInputPeriods);
    openFuturePeriods = openFP;
    cPeriod = new LocalDate(currentDate.withWeekOfWeekyear(1).withDayOfWeek(1));
    checkDate = new LocalDate(cPeriod);
    maxDate = new LocalDate(currentDate.getYear(), currentDate.getMonthOfYear(), currentDate.getDayOfMonth());
    maxDate = maxDate.minusDays(currentDate.getDayOfWeek());
    for (int i = 0; i < openFuturePeriods; i++) {
        maxDate = maxDate.plusWeeks(1);
    }
}
 
Example 10
Source File: WeekIterator.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))) && counter < quantity) {
        String year = checkDate.year().getAsString();
        String cWeekNumber = checkDate.weekOfWeekyear().getAsString();
        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: LocalDateIMMDateCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
/**
 * Assumes that the month is correct, get the day for the 2rd wednesday.
 *
 * @param original
 *            the start date
 * @return the 3rd Wednesday of the month
 */
private LocalDate calculate3rdWednesday(final LocalDate original) {
    final LocalDate firstOfMonth = original.withDayOfMonth(1);
    LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
    if (firstWed.isBefore(firstOfMonth)) {
        firstWed = firstWed.plusWeeks(1);
    }
    return firstWed.plusWeeks(2);
}
 
Example 12
Source File: WeekCalendar.java    From NCalendar with Apache License 2.0 4 votes vote down vote up
@Override
protected LocalDate getIntervalDate(LocalDate localDate, int count) {
    return localDate.plusWeeks(count);
}