@@ -0,0 +1,2338 @@
+package com.levelup.java.date.adjuster;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.time.LocalDate;%0Aimport java.time.Month;%0Aimport java.time.YearMonth;%0Aimport java.time.temporal.IsoFields;%0Aimport java.time.temporal.Temporal;%0Aimport java.time.temporal.TemporalAdjuster;%0Aimport java.time.temporal.TemporalAdjusters;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * This java example will demonstrate getting the last day in the quarter.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/examples/last-day-of-quarter-java8-adjuster/'%3ELast day of quarter%3C/a%3E%0A */%0Apublic class LastDayOfQuarter implements TemporalAdjuster %7B%0A%0A%09@Override%0A%09public Temporal adjustInto(Temporal temporal) %7B%0A%0A%09%09int currentQuarter = YearMonth.from(temporal).get(%0A%09%09%09%09IsoFields.QUARTER_OF_YEAR);%0A%0A%09%09if (currentQuarter == 1) %7B%0A%0A%09%09%09return LocalDate.from(temporal).withMonth(Month.MARCH.getValue())%0A%09%09%09%09%09.with(TemporalAdjusters.lastDayOfMonth());%0A%0A%09%09%7D else if (currentQuarter == 2) %7B%0A%0A%09%09%09return LocalDate.from(temporal).withMonth(Month.JUNE.getValue())%0A%09%09%09%09%09.with(TemporalAdjusters.lastDayOfMonth());%0A%0A%09%09%7D else if (currentQuarter == 3) %7B%0A%0A%09%09%09return LocalDate.from(temporal)%0A%09%09%09%09%09.withMonth(Month.SEPTEMBER.getValue())%0A%09%09%09%09%09.with(TemporalAdjusters.lastDayOfMonth());%0A%0A%09%09%7D else %7B%0A%0A%09%09%09return LocalDate.from(temporal).with(%0A%09%09%09%09%09TemporalAdjusters.lastDayOfYear());%0A%09%09%7D%0A%0A%09%7D%0A%0A%09@Test%0A%09public void first_quarter_last_day() %7B%0A%0A%09%09LocalDate date = LocalDate.of(2009, Month.FEBRUARY, 1);%0A%0A%09%09LocalDate firstQuarter = date.with(new LastDayOfQuarter());%0A%0A%09%09assertEquals(LocalDate.of(2009, Month.MARCH, 31), firstQuarter);%0A%09%7D%0A%0A%09@Test%0A%09public void second_quarter_last_day() %7B%0A%0A%09%09LocalDate date = LocalDate.of(2009, Month.MAY, 1);%0A%0A%09%09LocalDate secondQuarter = date.with(new LastDayOfQuarter());%0A%0A%09%09assertEquals(LocalDate.of(2009, Month.JUNE, 30), secondQuarter);%0A%09%7D%0A%0A%09@Test%0A%09public void third_quarter_last_day() %7B%0A%0A%09%09LocalDate date = LocalDate.of(2009, Month.AUGUST, 1);%0A%0A%09%09LocalDate thirdQuarter = date.with(new LastDayOfQuarter());%0A%0A%09%09assertEquals(LocalDate.of(2009, Month.SEPTEMBER, 30), thirdQuarter);%0A%09%7D%0A%0A%09@Test%0A%09public void fourth_quarter_first_day() %7B%0A%0A%09%09LocalDate date = LocalDate.of(2009, Month.NOVEMBER, 1);%0A%0A%09%09LocalDate fourthQuarter = date.with(new LastDayOfQuarter());%0A%0A%09%09assertEquals(LocalDate.of(2009, Month.DECEMBER, 31), fourthQuarter);%0A%09%7D%0A%0A%7D%0A

add last day of quarter example java 8 adjuster