Search in sources :

Example 36 with ZoneOffset

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

the class TCKZoneRules method test_Paris_preTimeZones.

public void test_Paris_preTimeZones() {
    ZoneRules test = europeParis();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

Example 37 with ZoneOffset

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

the class TCKZoneRules method test_NewYork_preTimeZones.

public void test_NewYork_preTimeZones() {
    ZoneRules test = americaNewYork();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.of("-04:56:02");
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

Example 38 with ZoneOffset

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

the class TestZoneId method test_NewYork_getOffset_toDST.

public void test_NewYork_getOffset_toDST() {
    ZoneId test = ZoneId.of("America/New_York");
    ZoneOffset offset = ZoneOffset.ofHours(-5);
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 8, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 9, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 10, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 11, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 12, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 13, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 14, offset)), ZoneOffset.ofHours(-4));
    // cutover at 02:00 local
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 9, 1, 59, 59, 999999999, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 9, 2, 0, 0, 0, offset)), ZoneOffset.ofHours(-4));
}
Also used : ZoneId(java.time.ZoneId) ZoneOffset(java.time.ZoneOffset)

Example 39 with ZoneOffset

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

the class TestDateTimeFormatterBuilder method test_appendOffset_parse.

@Test(dataProvider = "offsetPatterns")
public void test_appendOffset_parse(String pattern, int h, int m, int s, String expected) throws Exception {
    builder.appendOffset(pattern, "Z");
    DateTimeFormatter f = builder.toFormatter();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(h, m, s);
    ZoneOffset parsed = f.parse(expected, ZoneOffset::from);
    assertEquals(f.format(parsed), expected);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 40 with ZoneOffset

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

the class TCKLocalDateTime method test_toEpochSecond_afterEpoch.

//-----------------------------------------------------------------------
// toEpochSecond()
//-----------------------------------------------------------------------
@Test
public void test_toEpochSecond_afterEpoch() {
    for (int i = -5; i < 5; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        for (int j = 0; j < 100000; j++) {
            LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j);
            assertEquals(a.toEpochSecond(offset), j - i * 3600);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Aggregations

ZoneOffset (java.time.ZoneOffset)62 Test (org.testng.annotations.Test)35 LocalDateTime (java.time.LocalDateTime)9 ZoneRules (java.time.zone.ZoneRules)9 ZoneId (java.time.ZoneId)8 ZonedDateTime (java.time.ZonedDateTime)7 Instant (java.time.Instant)6 DateTimeFormatter (java.time.format.DateTimeFormatter)5 OffsetDateTime (java.time.OffsetDateTime)4 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)4 Clock (java.time.Clock)3 LocalTime (java.time.LocalTime)2 ChronoField (java.time.temporal.ChronoField)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 DateTimeException (java.time.DateTimeException)1 DayOfWeek (java.time.DayOfWeek)1 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 Month (java.time.Month)1