List of usage examples for org.joda.time YearMonth plusMonths
public YearMonth plusMonths(int months)
From source file:de.topobyte.joda.utils.MonthIterator.java
License:Open Source License
@Override public YearMonth next() { YearMonth current = next; next = current.plusMonths(1); return current; }
From source file:de.topobyte.joda.utils.MonthSpan.java
License:Open Source License
/** * Create a new span of months with the specified bounds. * /*from w ww . ja v a 2s.c o m*/ * @param limitLower * the lower limit, inclusive * @param numMonths * the number of months to span */ public MonthSpan(YearMonth limitLower, int numMonths) { this.limitLower = limitLower; empty = numMonths <= 0; if (empty) { limitUpper = limitLower; } else { limitUpper = limitLower.plusMonths(numMonths); } }
From source file:org.alexlg.bankit.controllers.AccountController.java
License:Open Source License
/** * Build categories summary for each month from startDate * to previous nbPrevMonth// w ww . j av a 2s . c o m * @param startDate Start the summary for this month * @param endDate Stop the summary for this month * @return Map with the date of the month and a Map with Category * and amount for this category for this month */ protected Map<Date, Map<Category, BigDecimal>> buildCategories(LocalDate startDate, LocalDate endDate) { Map<Date, Map<Category, BigDecimal>> categories = new LinkedHashMap<Date, Map<Category, BigDecimal>>(); YearMonth curMonth = null; //month we start to retrieve YearMonth endMonth = null; //last month we have to retrieve if (startDate.isBefore(endDate)) { curMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear()); endMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear()); } else { curMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear()); endMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear()); } do { Map<Category, BigDecimal> monthSummary = categoryDao.getMonthSummary(curMonth); if (monthSummary.size() > 0) { categories.put(curMonth.toLocalDate(1).toDate(), monthSummary); } curMonth = curMonth.plusMonths(1); } while (curMonth.isBefore(endMonth) || curMonth.isEqual(endMonth)); return categories; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
protected CalendarItem[] buildMonthItems() { YearMonth calendarFirstMonth = getCalendarFirstMonth(); YearMonth calendarLastMonth = getCalendarLastMonth(); YearMonth currentMonth = YearMonth.now(); int numberOfMonths = Months.monthsBetween(calendarFirstMonth, calendarLastMonth).getMonths() + 1; CalendarItem[] calendarItems = new CalendarItem[numberOfMonths]; YearMonth month = calendarFirstMonth; LocalDate currentValue = getLocalDate(); YearMonth currentYearMonthValue = currentValue == null ? null : new YearMonth(currentValue.getYear(), currentValue.getMonthOfYear()); for (int i = 0; i < numberOfMonths; i++, month = month.plusMonths(1)) { calendarItems[i] = new CalendarItem(); calendarItems[i].setIndex(i);/* w ww . j av a 2s. c om*/ calendarItems[i].setRelativeDateIndex(month.getMonthOfYear()); calendarItems[i].setEnabled(true); // By default StringBuilder style = new StringBuilder(""); if (month.equals(currentMonth)) { style.append("currentmonth "); } if (currentYearMonthValue != null && month.equals(currentYearMonthValue)) { style.append("selected "); } if (cellItemCustomizer != null) { String generatedStyle = cellItemCustomizer.getStyle(month, this); if (generatedStyle != null) { style.append(generatedStyle); style.append(" "); } String tooltip = cellItemCustomizer.getTooltip(month, this); if (tooltip != null) { calendarItems[i].setTooltip(tooltip); } } if (isMonthEnabled(month)) { calendarItems[i].setEnabled(true); } String computedStyle = style.toString(); if (!computedStyle.isEmpty()) { calendarItems[i].setStyle(computedStyle); } String calendarItemContent = null; if (cellItemCustomizer != null) { calendarItemContent = cellItemCustomizer.renderMonth(currentYearMonthValue, this); } // fallback to default value if (calendarItemContent == null) { calendarItemContent = shortMonthTexts[i]; } calendarItems[i].setText(calendarItemContent); } return calendarItems; }