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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations