use of java.time.Year in project SimpleFlatMapper by arnaudroger.
the class SettableDataSetterFactoryTest method testJava8TimeYear.
@Test
public void testJava8TimeYear() throws Exception {
Setter<SettableByIndexData, Year> setter = factory.getSetter(newPM(Year.class, DataType.date()));
Year ldt = Year.now();
setter.set(statement, ldt);
setter.set(statement, null);
verify(statement).setDate(0, com.datastax.driver.core.LocalDate.fromYearMonthDay(ldt.getValue(), 1, 1));
verify(statement).setToNull(0);
}
use of java.time.Year in project SimpleFlatMapper by arnaudroger.
the class JavaTimeConverterServiceTest method testObjectToYear.
@Test
public void testObjectToYear() throws Exception {
ZoneId zoneId = ZONE_ID;
Date now = new Date();
Year year = Year.from(now.toInstant().atZone(zoneId));
testObjectToYear(null, null);
testObjectToYear(year, year);
testObjectToYear(year.atMonth(6).atEndOfMonth().atTime(1, 0).atZone(zoneId), year);
testObjectToYear(now, year);
testObjectToYear(year.getValue(), year);
try {
testObjectToYear("a string", year);
fail();
} catch (IllegalArgumentException e) {
// expected
}
}
use of java.time.Year in project Java-Tutorial by gpcodervn.
the class YearMonthExample method main.
public static void main(String[] args) {
// Year Example
Year currentYear = Year.now();
// 2018
System.out.println("currentYear: " + currentYear);
Year specifyYear = Year.of(2016);
// 2016
System.out.println("specifyYear: " + specifyYear);
// true
System.out.println("isLeap : " + specifyYear.isLeap());
int dayOfYear = 100;
LocalDate localDate = currentYear.atDay(dayOfYear);
// 2018-04-10
System.out.println("localDate: " + localDate);
// YearMonth Example
YearMonth currentYearMonth = YearMonth.now();
System.out.println("currentYearMonth: " + currentYearMonth);
YearMonth specifyYearMonth = YearMonth.of(2016, 1);
System.out.println("specifyYearMonth: " + specifyYearMonth);
int dayOfMonth = 20;
LocalDate localDate2 = currentYearMonth.atDay(dayOfMonth);
// 2018-06-20
System.out.println("localDate2: " + localDate2);
// Year -> YearMonth
YearMonth ym = currentYear.atMonth(5);
// 2018-05
System.out.println("ym: " + ym);
}
Aggregations