List of usage examples for java.time YearMonth minusMonths
public YearMonth minusMonths(long monthsToSubtract)
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.now(); YearMonth s = y.minusMonths(12); System.out.println(s);/*w w w .j a va2 s . com*/ }
From source file:com.github.drbookings.LocalDates.java
public static boolean isPrevMonth(YearMonth selectedMonth, LocalDate date) { return YearMonth.from(date).equals(selectedMonth.minusMonths(1)); }
From source file:sg.ncl.MainController.java
private void differentiateProjects(List<ProjectDetails> newProjects, List<ProjectDetails> activeProjects, List<ProjectDetails> inactiveProjects, List<ProjectDetails> stoppedProjects, YearMonth m_s, YearMonth m_e, ProjectDetails project) { YearMonth created = YearMonth.from(project.getZonedDateCreated()); YearMonth m_e_m1 = m_e.minusMonths(1); YearMonth m_e_m2 = m_e.minusMonths(2); YearMonth m_active = m_e_m2.isBefore(m_s) ? m_e_m2 : m_s; // projects created within the period if (!(created.isBefore(m_s) || created.isAfter(m_e))) { newProjects.add(project);/*from ww w. j av a 2 s . c om*/ } // active projects = projects with resources within the period + projects created boolean hasUsage = project.getProjectUsages().stream().anyMatch(p -> p.hasUsageWithinPeriod(m_active, m_e)); if (hasUsage || !(created.isBefore(m_e_m2) || created.isAfter(m_e))) { activeProjects.add(project); } // inactive projects if (!hasUsage && created.isBefore(m_e_m2)) { inactiveProjects.add(project); } // stopped projects boolean hasUsagePreviousMonth = project.getProjectUsages().stream() .anyMatch(p -> p.hasUsageWithinPeriod(m_e_m1, m_e_m1)); boolean hasUsageCurrentMonth = project.getProjectUsages().stream() .anyMatch(p -> p.hasUsageWithinPeriod(m_e, m_e)); if (hasUsagePreviousMonth && !hasUsageCurrentMonth) { stoppedProjects.add(project); } }