Search in sources :

Example 1 with ZoneOffset

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

the class TCKZonedDateTime method test_get.

@Test(dataProvider = "sampleTimes")
public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) {
    LocalDate localDate = LocalDate.of(y, o, d);
    LocalTime localTime = LocalTime.of(h, m, s, n);
    LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
    ZoneOffset offset = zone.getRules().getOffset(localDateTime);
    ZonedDateTime a = ZonedDateTime.of(localDateTime, zone);
    assertEquals(a.getYear(), localDate.getYear());
    assertEquals(a.getMonth(), localDate.getMonth());
    assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
    assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
    assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
    assertEquals(a.getHour(), localTime.getHour());
    assertEquals(a.getMinute(), localTime.getMinute());
    assertEquals(a.getSecond(), localTime.getSecond());
    assertEquals(a.getNano(), localTime.getNano());
    assertEquals(a.toLocalDate(), localDate);
    assertEquals(a.toLocalTime(), localTime);
    assertEquals(a.toLocalDateTime(), localDateTime);
    if (zone instanceof ZoneOffset) {
        assertEquals(a.toString(), localDateTime.toString() + offset.toString());
    } else {
        assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) ZonedDateTime(java.time.ZonedDateTime) LocalDate(java.time.LocalDate) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 2 with ZoneOffset

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

the class TCKZonedDateTime method now_Clock_offsets.

@Test
public void now_Clock_offsets() {
    ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(1970, 1, 1, 12, 0), ZoneOffset.UTC);
    for (int i = -9; i < 15; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        Clock clock = Clock.fixed(base.toInstant(), offset);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test.getHour(), (12 + i) % 24);
        assertEquals(test.getMinute(), 0);
        assertEquals(test.getSecond(), 0);
        assertEquals(test.getNano(), 0);
        assertEquals(test.getOffset(), offset);
        assertEquals(test.getZone(), offset);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Clock(java.time.Clock) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 3 with ZoneOffset

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

the class TCKZoneOffset method test_factory_int_hours.

//-----------------------------------------------------------------------
@Test
public void test_factory_int_hours() {
    for (int i = -18; i <= 18; i++) {
        ZoneOffset test = ZoneOffset.ofHours(i);
        doTestOffset(test, i, 0, 0);
    }
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 4 with ZoneOffset

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

the class TCKZoneOffset method test_factory_int_hours_minutes_seconds.

//-----------------------------------------------------------------------
@Test
public void test_factory_int_hours_minutes_seconds() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            for (int k = -59; k <= 59; k++) {
                if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) || (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) {
                    ZoneOffset test = ZoneOffset.ofHoursMinutesSeconds(i, j, k);
                    doTestOffset(test, i, j, k);
                }
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0);
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.ofHoursMinutesSeconds(18, 0, 0);
    doTestOffset(test2, 18, 0, 0);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 5 with ZoneOffset

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

the class TCKZoneOffset method test_equals.

//-----------------------------------------------------------------------
// equals() / hashCode()
//-----------------------------------------------------------------------
@Test
public void test_equals() {
    ZoneOffset offset1 = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
    ZoneOffset offset2 = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
    ZoneOffset offset2b = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
    assertEquals(offset1.equals(offset2), false);
    assertEquals(offset2.equals(offset1), false);
    assertEquals(offset1.equals(offset1), true);
    assertEquals(offset2.equals(offset2), true);
    assertEquals(offset2.equals(offset2b), true);
    assertEquals(offset1.hashCode() == offset1.hashCode(), true);
    assertEquals(offset2.hashCode() == offset2.hashCode(), true);
    assertEquals(offset2.hashCode() == offset2b.hashCode(), true);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Aggregations

ZoneOffset (java.time.ZoneOffset)197 Test (org.junit.Test)51 ZoneId (java.time.ZoneId)35 Test (org.testng.annotations.Test)35 LocalDateTime (java.time.LocalDateTime)34 ZonedDateTime (java.time.ZonedDateTime)26 ZoneRules (java.time.zone.ZoneRules)23 LocalTime (java.time.LocalTime)22 OffsetDateTime (java.time.OffsetDateTime)17 Instant (java.time.Instant)16 LocalDate (java.time.LocalDate)14 TemporalAccessor (java.time.temporal.TemporalAccessor)11 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)11 DateTimeFormatter (java.time.format.DateTimeFormatter)9 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)7 OffsetTime (java.time.OffsetTime)7 ArrayList (java.util.ArrayList)6 Clock (java.time.Clock)5 DateTimeException (java.time.DateTimeException)5 TemporalField (java.time.temporal.TemporalField)5