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

The following examples show how to use org.joda.time.LocalDate#withDayOfWeek() . 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: MyConfig.java    From CalendarPicker with MIT License 6 votes vote down vote up
public static CalendarWeek getWeekIncludeThisDay(LocalDate localDate) {

        LocalDate monday = localDate.withDayOfWeek(DateTimeConstants.MONDAY);
        LocalDate tuesday = localDate.withDayOfWeek(DateTimeConstants.TUESDAY);
        LocalDate wednesday = localDate.withDayOfWeek(DateTimeConstants.WEDNESDAY);
        LocalDate thursday = localDate.withDayOfWeek(DateTimeConstants.THURSDAY);
        LocalDate friday = localDate.withDayOfWeek(DateTimeConstants.FRIDAY);
        LocalDate saturday = localDate.withDayOfWeek(DateTimeConstants.SATURDAY);
        LocalDate sunday = localDate.withDayOfWeek(DateTimeConstants.SUNDAY);

        CalendarWeek calendarWeek = new CalendarWeek(
                monday,
                tuesday,
                wednesday,
                thursday,
                friday,
                saturday,
                sunday
        );
        calendarWeek.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);
        calendarWeek.originDate = localDate;

        return calendarWeek;
    }
 
Example 2
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 3
Source File: WeeklyExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected LocalDate getMaxDateCanEdit() {
    LocalDate periodDate = LocalDate.parse(period, DateTimeFormat.forPattern(getDateFormat()));
    periodDate = periodDate.withDayOfWeek(weekStarts());
    periodDate = periodDate.plusDays(6);
    return periodDate.plusDays(expiryDays - 1);
}
 
Example 4
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);
}