Search in sources :

Example 11 with ZoneId

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

the class TCKZonedDateTime method now_Clock_allSecsInDay_zone.

@Test
public void now_Clock_allSecsInDay_zone() {
    ZoneId zone = ZoneId.of("Europe/London");
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        ZonedDateTime expected = ZonedDateTime.ofInstant(instant, zone);
        Clock clock = Clock.fixed(expected.toInstant(), zone);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test, expected);
    }
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 12 with ZoneId

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

the class TCKZonedDateTime method now_ZoneId.

@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone));
    ZonedDateTime test = ZonedDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = ZonedDateTime.now(Clock.system(zone));
        test = ZonedDateTime.now(zone);
    }
    assertEquals(test, expected);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.testng.annotations.Test)

Example 13 with ZoneId

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

the class TCKZoneId method test_invalidPrefixOfOffset.

@Test(dataProvider = "prefixInvalid", expectedExceptions = java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    fail("should have thrown an exception for prefix: " + prefix);
}
Also used : ZoneId(java.time.ZoneId) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 14 with ZoneId

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

the class TCKZoneId method test_of_string_Map.

//-----------------------------------------------------------------------
// mapped factory
//-----------------------------------------------------------------------
@Test
public void test_of_string_Map() {
    Map<String, String> map = new HashMap<>();
    map.put("LONDON", "Europe/London");
    map.put("PARIS", "Europe/Paris");
    ZoneId test = ZoneId.of("LONDON", map);
    assertEquals(test.getId(), "Europe/London");
}
Also used : ZoneId(java.time.ZoneId) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 15 with ZoneId

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

the class TCKZoneId method factory_of_String_offsetBasedValid_prefixUTC.

@Test(dataProvider = "offsetBasedValidPrefix")
public void factory_of_String_offsetBasedValid_prefixUTC(String input, String id, String offsetId) {
    ZoneId test = ZoneId.of("UTC" + input);
    assertEquals(test.getId(), "UTC" + id);
    assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
    assertEquals(test.normalized(), ZoneOffset.of(offsetId));
    assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), displayName("UTC" + id));
    assertEquals(test.getRules().isFixedOffset(), true);
    assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(offsetId));
}
Also used : ZoneId(java.time.ZoneId) Test(org.testng.annotations.Test)

Aggregations

ZoneId (java.time.ZoneId)88 Test (org.testng.annotations.Test)38 LocalDateTime (java.time.LocalDateTime)13 ZonedDateTime (java.time.ZonedDateTime)13 Test (org.junit.Test)8 Clock (java.time.Clock)7 ZoneOffset (java.time.ZoneOffset)7 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)6 Chronology (java.time.chrono.Chronology)5 IsoChronology (java.time.chrono.IsoChronology)5 AbstractTCKTest (tck.java.time.AbstractTCKTest)5 Instant (java.time.Instant)4 HijrahChronology (java.time.chrono.HijrahChronology)4 JapaneseChronology (java.time.chrono.JapaneseChronology)4 MinguoChronology (java.time.chrono.MinguoChronology)4 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)4 LocalTime (java.time.LocalTime)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 HashMap (java.util.HashMap)3 Field (java.lang.reflect.Field)2