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

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

        CalendarMonth calendarMonth = new CalendarMonth();

        calendarMonth.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);

        for (int i = 0; i < 6; i++) {//每个月最多6周,最少4周
            CalendarWeek w = getWeekIncludeThisDay(calendarMonth.firstDayOfCurrentMonth.plusDays(7 * i));

            if (i < 4) {
                calendarMonth.calendarWeeks.addLast(w);
            } else if (w.calendarDayList.getFirst().day.getMonthOfYear() == calendarMonth.firstDayOfCurrentMonth.getMonthOfYear()) {
                /**
                 * 从第5周开始检
                 * 如果w的第一天的月份等于本月第一天的月份,那么这一周也算本月的周
                 */
                calendarMonth.calendarWeeks.addLast(w);
            } else {
                break;
            }

        }
        calendarMonth.originDate = localDate;

        return calendarMonth;
    }
 
Example 3
Source File: DateRangeStaticFacotry.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public static Collection<DateRange> splitAsDateRangeByMonth(LocalDate start, LocalDate end){
	
	Set<DateRange> dates = new LinkedHashSet<DateRange>();
	dates.add(new DateRange(start, start.withDayOfMonth(start.dayOfMonth().getMaximumValue())));
	
	LocalDate startDateOfMonth = start.withDayOfMonth(start.dayOfMonth().getMinimumValue()).plusMonths(1);
	while(!startDateOfMonth.isAfter(end)){
		LocalDate endDateOfWeek = startDateOfMonth.withDayOfMonth(startDateOfMonth.dayOfMonth().getMaximumValue());
		if(endDateOfWeek.isAfter(end)){
			endDateOfWeek = end;
		}
		DateRange dr = new DateRange(startDateOfMonth, endDateOfWeek);
		dates.add(dr);
		startDateOfMonth = startDateOfMonth.plusMonths(1);
	}
	return dates;
}
 
Example 4
Source File: ImsakiyeFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public ImsakiyeAdapter(Context context) {
    LocalDate now = LocalDate.now();
    today = now.getDayOfMonth();
    date = now.withDayOfMonth(1);
    daysInMonth = date.dayOfMonth().getMaximumValue();


    inflater = LayoutInflater.from(context);
}
 
Example 5
Source File: ImsakiyeFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public ImsakiyeAdapter(Context context) {
    LocalDate now = LocalDate.now();
    today = now.getDayOfMonth();
    date = now.withDayOfMonth(1);
    daysInMonth = date.dayOfMonth().getMaximumValue();


    inflater = LayoutInflater.from(context);
}
 
Example 6
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 7
Source File: TurnoverAnalysisService.java    From estatio with Apache License 2.0 5 votes vote down vote up
LocalDate getStartDateToUse(final AggregationAnalysisReportForConfig report){
    final Occupancy occupancy = report.getTurnoverReportingConfig().getOccupancy();
    LocalDate occStartDateOrNull = null;
    try {
        occStartDateOrNull = occupancy.getEffectiveInterval().startDate();
    } catch (Exception e) {
        LOG.warn(String.format("Problem with occupancy %s on lease %s", occupancy.toString(), occupancy.getLease().getReference()));
        LOG.warn(e.getMessage());
    }

    return occStartDateOrNull == null ? TurnoverAggregationService.MIN_AGGREGATION_DATE : occStartDateOrNull.withDayOfMonth(1);

}
 
Example 8
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 9
Source File: CalendarUtil.java    From NCalendar with Apache License 2.0 4 votes vote down vote up
/**
 * 获得两个日期距离几个月
 *
 * @return
 */
public static int getIntervalMonths(LocalDate date1, LocalDate date2) {
    date1 = date1.withDayOfMonth(1);
    date2 = date2.withDayOfMonth(1);
    return Months.monthsBetween(date1, date2).getMonths();
}