Search in sources :

Example 31 with LocalDateTime

use of java.time.LocalDateTime in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_minusDays_overMonths.

@Test
public void test_minusDays_overMonths() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(62);
    check(t, 2007, 5, 14, 12, 30, 40, 987654321);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Example 32 with LocalDateTime

use of java.time.LocalDateTime in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_minusDays_overYears.

@Test
public void test_minusDays_overYears() {
    LocalDateTime t = LocalDateTime.of(2008, 7, 16, 12, 30, 40, 987654321).minusDays(367);
    assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Example 33 with LocalDateTime

use of java.time.LocalDateTime in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_hashCode.

//-----------------------------------------------------------------------
// hashCode()
//-----------------------------------------------------------------------
@Test(dataProvider = "sampleDateTimes")
public void test_hashCode(int y, int m, int d, int h, int mi, int s, int n) {
    LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
    assertEquals(a.hashCode(), a.hashCode());
    LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
    assertEquals(a.hashCode(), b.hashCode());
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Example 34 with LocalDateTime

use of java.time.LocalDateTime in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_getDayOfWeek.

//-----------------------------------------------------------------------
// getDayOfWeek()
//-----------------------------------------------------------------------
@Test
public void test_getDayOfWeek() {
    DayOfWeek dow = DayOfWeek.MONDAY;
    for (Month month : Month.values()) {
        int length = month.length(false);
        for (int i = 1; i <= length; i++) {
            LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i), TEST_2007_07_15_12_30_40_987654321.toLocalTime());
            assertSame(d.getDayOfWeek(), dow);
            dow = dow.plus(1);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DayOfWeek(java.time.DayOfWeek) Month(java.time.Month) Test(org.testng.annotations.Test)

Example 35 with LocalDateTime

use of java.time.LocalDateTime in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_plusNanos_halfABillion.

//-----------------------------------------------------------------------
// plusNanos()
//-----------------------------------------------------------------------
@Test
public void test_plusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();
    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;
    for (long i = 0; i < 3700 * 1000000000L; i += 500000000) {
        t = t.plusNanos(500000000);
        nanos += 500000000;
        if (nanos == 1000000000) {
            sec++;
            nanos = 0;
        }
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }
        assertEquals(t.toLocalDate(), d, String.valueOf(i));
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

LocalDateTime (java.time.LocalDateTime)486 Test (org.testng.annotations.Test)282 Test (org.junit.Test)67 ZonedDateTime (java.time.ZonedDateTime)53 LocalDate (java.time.LocalDate)49 LocalTime (java.time.LocalTime)28 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)26 Instant (java.time.Instant)21 DateTimeFormatter (java.time.format.DateTimeFormatter)20 List (java.util.List)18 Date (java.util.Date)17 ZoneId (java.time.ZoneId)16 ArrayList (java.util.ArrayList)14 AbstractTCKTest (tck.java.time.AbstractTCKTest)14 HashMap (java.util.HashMap)12 OffsetDateTime (java.time.OffsetDateTime)11 ZoneOffset (java.time.ZoneOffset)11 DateTimeParseException (java.time.format.DateTimeParseException)11 ZoneRules (java.time.zone.ZoneRules)10 IOException (java.io.IOException)9