Search in sources :

Example 16 with LocalDateTime

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

the class TCKLocalDateTime method test_plusYears_int_normal.

//-----------------------------------------------------------------------
// plusYears()
//-----------------------------------------------------------------------
@Test
public void test_plusYears_int_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(1);
    check(t, 2008, 7, 15, 12, 30, 40, 987654321);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Example 17 with LocalDateTime

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

the class TCKLocalDateTime method test_minusWeeks_overMonths.

@Test
public void test_minusWeeks_overMonths() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(9);
    check(t, 2007, 5, 13, 12, 30, 40, 987654321);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Example 18 with LocalDateTime

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

the class TCKLocalDateTime method test_minusNanos_halfABillion.

//-----------------------------------------------------------------------
// minusNanos()
//-----------------------------------------------------------------------
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);
    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;
    for (long i = 0; i < 3700 * 1000000000L; i += 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;
        if (nanos < 0) {
            sec--;
            nanos += 1000000000;
            if (sec == -1) {
                min--;
                sec += 60;
                if (min == -1) {
                    hour--;
                    min += 60;
                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }
        assertEquals(t.toLocalDate(), d);
        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)

Example 19 with LocalDateTime

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

the class TCKLocalDateTime method test_toString.

@Test(dataProvider = "sampleToString")
public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Example 20 with LocalDateTime

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

the class TCKLocalDateTime method test_plusWeeks_overYears.

@Test
public void test_plusWeeks_overYears() {
    LocalDateTime t = LocalDateTime.of(2006, 7, 16, 12, 30, 40, 987654321).plusWeeks(52);
    assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Aggregations

LocalDateTime (java.time.LocalDateTime)399 Test (org.testng.annotations.Test)280 ZonedDateTime (java.time.ZonedDateTime)45 Test (org.junit.Test)40 LocalDate (java.time.LocalDate)33 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)26 LocalTime (java.time.LocalTime)20 Instant (java.time.Instant)19 DateTimeFormatter (java.time.format.DateTimeFormatter)16 ZoneId (java.time.ZoneId)15 AbstractTCKTest (tck.java.time.AbstractTCKTest)14 OffsetDateTime (java.time.OffsetDateTime)10 ZoneRules (java.time.zone.ZoneRules)10 ZoneOffset (java.time.ZoneOffset)9 Date (java.util.Date)8 List (java.util.List)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Timestamp (java.sql.Timestamp)6 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)6