Search in sources :

Example 11 with ZoneOffset

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

the class TCKZoneOffset method test_constant_UTC.

//-----------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------
@Test
public void test_constant_UTC() {
    ZoneOffset test = ZoneOffset.UTC;
    doTestOffset(test, 0, 0, 0);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 12 with ZoneOffset

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

the class TCKDateTimeFormatterBuilder 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 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 13 with ZoneOffset

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

the class TCKZoneRules method test_NewYork_getOffset_toDST.

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

Example 14 with ZoneOffset

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

the class TCKZoneRules method test_NewYork_getOffset.

public void test_NewYork_getOffset() {
    ZoneRules test = americaNewYork();
    ZoneOffset offset = ZoneOffset.ofHours(-5);
    assertEquals(test.getOffset(createInstant(2008, 1, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 2, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 3, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 4, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 5, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 6, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 7, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 8, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 9, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 10, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 11, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 12, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 1, 28, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 2, 28, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 3, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 4, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 5, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 6, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 7, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 8, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 9, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 10, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 11, 28, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 12, 28, offset)), ZoneOffset.ofHours(-5));
}
Also used : ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

Example 15 with ZoneOffset

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

the class TCKZoneRules method test_NewYork_getOffset_fromDST.

public void test_NewYork_getOffset_fromDST() {
    ZoneRules test = americaNewYork();
    ZoneOffset offset = ZoneOffset.ofHours(-4);
    assertEquals(test.getOffset(createInstant(2008, 11, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 11, 2, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 11, 3, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 11, 4, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 11, 5, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 11, 6, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(createInstant(2008, 11, 7, offset)), ZoneOffset.ofHours(-5));
    // cutover at 02:00 local
    assertEquals(test.getOffset(createInstant(2008, 11, 2, 1, 59, 59, 999999999, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(createInstant(2008, 11, 2, 2, 0, 0, 0, offset)), ZoneOffset.ofHours(-5));
}
Also used : ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

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