Search in sources :

Example 26 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_getTransitionRules_immutable.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void test_getTransitionRules_immutable() {
    ZoneRules test = europeParis();
    test.getTransitionRules().clear();
}
Also used : ZoneRules(java.time.zone.ZoneRules) Test(org.testng.annotations.Test)

Example 27 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_Paris_getOffset.

public void test_Paris_getOffset() {
    ZoneRules test = europeParis();
    assertEquals(test.getOffset(createInstant(2008, 1, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 2, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 3, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 4, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 5, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 6, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 7, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 8, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 9, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 10, 1, ZoneOffset.UTC)), OFFSET_PTWO);
    assertEquals(test.getOffset(createInstant(2008, 11, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 12, 1, ZoneOffset.UTC)), OFFSET_PONE);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Example 28 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_London_getOffset.

public void test_London_getOffset() {
    ZoneRules test = europeLondon();
    assertEquals(test.getOffset(createInstant(2008, 1, 1, ZoneOffset.UTC)), OFFSET_ZERO);
    assertEquals(test.getOffset(createInstant(2008, 2, 1, ZoneOffset.UTC)), OFFSET_ZERO);
    assertEquals(test.getOffset(createInstant(2008, 3, 1, ZoneOffset.UTC)), OFFSET_ZERO);
    assertEquals(test.getOffset(createInstant(2008, 4, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 5, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 6, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 7, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 8, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 9, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 10, 1, ZoneOffset.UTC)), OFFSET_PONE);
    assertEquals(test.getOffset(createInstant(2008, 11, 1, ZoneOffset.UTC)), OFFSET_ZERO);
    assertEquals(test.getOffset(createInstant(2008, 12, 1, ZoneOffset.UTC)), OFFSET_ZERO);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Example 29 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_Paris_getOffsetInfo.

public void test_Paris_getOffsetInfo() {
    ZoneRules test = europeParis();
    checkOffset(test, createLDT(2008, 1, 1), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 2, 1), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 3, 1), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 4, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 5, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 6, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 7, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 8, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 9, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 1), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 11, 1), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 12, 1), OFFSET_PONE, 1);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Example 30 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class OffsetTime method ofInstant.

//-----------------------------------------------------------------------
/**
     * Obtains an instance of {@code OffsetTime} from an {@code Instant} and zone ID.
     * <p>
     * This creates an offset time with the same instant as that specified.
     * Finding the offset from UTC/Greenwich is simple as there is only one valid
     * offset for each instant.
     * <p>
     * The date component of the instant is dropped during the conversion.
     * This means that the conversion can never fail due to the instant being
     * out of the valid range of dates.
     *
     * @param instant  the instant to create the time from, not null
     * @param zone  the time-zone, which may be an offset, not null
     * @return the offset time, not null
     */
public static OffsetTime ofInstant(Instant instant, ZoneId zone) {
    Objects.requireNonNull(instant, "instant");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    ZoneOffset offset = rules.getOffset(instant);
    // overflow caught later
    long localSecond = instant.getEpochSecond() + offset.getTotalSeconds();
    int secsOfDay = (int) Math.floorMod(localSecond, SECONDS_PER_DAY);
    LocalTime time = LocalTime.ofNanoOfDay(secsOfDay * NANOS_PER_SECOND + instant.getNano());
    return new OffsetTime(time, offset);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Aggregations

ZoneRules (java.time.zone.ZoneRules)68 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)22 LocalDateTime (java.time.LocalDateTime)10 Test (org.testng.annotations.Test)10 Instant (java.time.Instant)9 ZoneOffset (java.time.ZoneOffset)9 ZonedDateTime (java.time.ZonedDateTime)9 ZoneOffsetTransitionRule (java.time.zone.ZoneOffsetTransitionRule)5 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 OffsetDateTime (java.time.OffsetDateTime)1 TimeDefinition (java.time.zone.ZoneOffsetTransitionRule.TimeDefinition)1 ZoneRulesException (java.time.zone.ZoneRulesException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1