Search in sources :

Example 71 with Year

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);
}
Also used : Year(java.time.Year) Test(org.junit.Test)

Example 72 with Year

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
    }
}
Also used : ZoneId(java.time.ZoneId) Year(java.time.Year) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 73 with Year

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);
}
Also used : Year(java.time.Year) YearMonth(java.time.YearMonth) LocalDate(java.time.LocalDate)

Aggregations

Year (java.time.Year)73 Test (org.junit.Test)35 Test (org.testng.annotations.Test)33 LocalDate (java.time.LocalDate)8 YearMonth (java.time.YearMonth)4 ZoneId (java.time.ZoneId)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Clock (java.time.Clock)2 DateTimeException (java.time.DateTimeException)2 Instant (java.time.Instant)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 DateTimeParseException (java.time.format.DateTimeParseException)2 Temporal (java.time.temporal.Temporal)2 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)2 Test (org.junit.jupiter.api.Test)2 LocalDateTime (java.time.LocalDateTime)1 ZonedDateTime (java.time.ZonedDateTime)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 Date (java.util.Date)1