@@ -0,0 +1,1959 @@
+package com.levelup.java.date.query;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.time.LocalDate;%0Aimport java.time.Month;%0Aimport java.time.temporal.ChronoField;%0Aimport java.time.temporal.TemporalAccessor;%0Aimport java.time.temporal.TemporalQuery;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * This java example will demonstrate finding the current quarter.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/examples/current-quarter-temporal-query-java8/'%3ECurrent quarter query%3C/a%3E%0A */%0Apublic class CurrentQuarterQuery implements TemporalQuery%3CInteger%3E %7B%0A%0A%09/* (non-Javadoc)%0A%09 * @see java.time.temporal.TemporalQuery#queryFrom(java.time.temporal.TemporalAccessor)%0A%09 */%0A%09@Override%0A%09public Integer queryFrom(TemporalAccessor date) %7B%0A%09%09%0A%09%09int month = date.get(ChronoField.MONTH_OF_YEAR);%0A%09%09%0A%09%09if (month %3C= Month.MARCH.getValue()) %7B%0A%09%09%09return new Integer(1);%0A%09%09%7D else if (month %3C= Month.JUNE.getValue()) %7B%0A%09%09%09return new Integer(2);%0A%09%09%7D else if (month %3C= Month.SEPTEMBER.getValue()) %7B%0A%09%09%09return new Integer(3);%0A%09%09%7D else %7B%0A%09%09%09return new Integer(4);%0A%09%09%7D%0A%09%7D%0A%09%0A%09%0A%09@Test%0A%09public void validate_first_quarter () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, Month.MARCH, 4); %0A%0A%09%09Integer quarter = date.query(new CurrentQuarterQuery());%0A%09%09%0A%09%09assertEquals(new Integer(1), quarter);%0A%09%7D%0A%0A%09%0A%09@Test%0A%09public void validate_second_quarter () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, Month.MAY, 8); %0A%0A%09%09Integer quarter = date.query(new CurrentQuarterQuery());%0A%09%09%0A%09%09assertEquals(new Integer(2), quarter);%0A%09%7D%0A%0A%09%0A%09@Test%0A%09public void validate_third_quarter () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, Month.SEPTEMBER, 2); %0A%0A%09%09Integer quarter = date.query(new CurrentQuarterQuery());%0A%09%09%0A%09%09assertEquals(new Integer(3), quarter);%0A%09%7D%0A%0A%09%0A%09@Test%0A%09public void validate_fourth_quarter () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, Month.DECEMBER, 18); %0A%0A%09%09Integer quarter = date.query(new CurrentQuarterQuery());%0A%09%09%0A%09%09assertEquals(new Integer(4), quarter);%0A%09%7D%0A%09%0A%7D%0A

add current quarter query java 8 temporal query