java.time.zone.ZoneRules Java Examples

The following examples show how to use java.time.zone.ZoneRules. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TCKZoneRules.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void test_Paris_getStandardOffset() {
    ZoneRules test = europeParis();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21));
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        }
        zdt = zdt.plusMonths(6);
    }
}
 
Example #2
Source File: TCKFixedZoneRules.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_equalsHashCode() {
    ZoneRules a = make(OFFSET_PONE);
    ZoneRules b = make(OFFSET_PTWO);

    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(b.equals(b), true);

    assertEquals(a.equals("Rubbish"), false);
    assertEquals(a.equals(null), false);

    assertEquals(a.hashCode() == a.hashCode(), true);
    assertEquals(b.hashCode() == b.hashCode(), true);
}
 
Example #3
Source File: TCKZoneRules.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void test_London_getOffsetInfo_overlap() {
    ZoneRules test = europeLondon();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 10, 26, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PONE, OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), OFFSET_PONE);
    assertEquals(trans.getOffsetAfter(), OFFSET_ZERO);
    assertEquals(trans.getInstant(), createInstant(2008, 10, 26, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 10, 26, 2, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 10, 26, 1, 0));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(OFFSET_ZERO), true);
    assertEquals(trans.isValidOffset(OFFSET_PONE), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-10-26T02:00+01:00 to Z]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_PONE));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #4
Source File: TCKZoneRules.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void test_London_nextTransition_rulesBased() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    List<ZoneOffsetTransition> trans = test.getTransitions();

    ZoneOffsetTransition last = trans.get(trans.size() - 1);
    assertEquals(test.nextTransition(last.getInstant()), rules.get(0).createTransition(1998));

    for (int year = 1998; year < 2010; year++) {
        ZoneOffsetTransition a = rules.get(0).createTransition(year);
        ZoneOffsetTransition b = rules.get(1).createTransition(year);
        ZoneOffsetTransition c = rules.get(0).createTransition(year + 1);

        assertEquals(test.nextTransition(a.getInstant()), b);
        assertEquals(test.nextTransition(b.getInstant().minusNanos(1)), b);

        assertEquals(test.nextTransition(b.getInstant()), c);
        assertEquals(test.nextTransition(c.getInstant().minusNanos(1)), c);
    }
}
 
Example #5
Source File: TCKZoneRules.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void test_Apia_jumpOverInternationalDateLine_M10_to_P14() {
    // transition occurred at 2011-12-30T00:00-10:00
    ZoneRules test = pacificApia();
    Instant instantBefore = LocalDate.of(2011, 12, 27).atStartOfDay(ZoneOffset.UTC).toInstant();
    ZoneOffsetTransition trans = test.nextTransition(instantBefore);
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2011, 12, 30, 0, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2011, 12, 31, 0, 0));
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-10)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(+14)), false);
    assertEquals(trans.getDuration(), Duration.ofHours(24));
    assertEquals(trans.getInstant(), LocalDateTime.of(2011, 12, 31, 0, 0).toInstant(ZoneOffset.ofHours(+14)));

    ZonedDateTime zdt = ZonedDateTime.of(2011, 12, 29, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
    assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(2011, 12, 31, 1, 0));
}
 
Example #6
Source File: TCKFixedZoneRules.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_equalsHashCode() {
    ZoneRules a = make(OFFSET_PONE);
    ZoneRules b = make(OFFSET_PTWO);

    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(b.equals(b), true);

    assertEquals(a.equals("Rubbish"), false);
    assertEquals(a.equals(null), false);

    assertEquals(a.hashCode() == a.hashCode(), true);
    assertEquals(b.hashCode() == b.hashCode(), true);
}
 
Example #7
Source File: TCKZoneRules.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #8
Source File: TCKZoneRules.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #9
Source File: TCKZoneRules.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void test_London_getOffsetInfo_gap() {
    ZoneRules test = europeLondon();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_ZERO, GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), OFFSET_ZERO);
    assertEquals(trans.getOffsetAfter(), OFFSET_PONE);
    assertEquals(trans.getInstant(), createInstant(2008, 3, 30, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 3, 30, 1, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 3, 30, 2, 0));
    assertEquals(trans.isValidOffset(OFFSET_ZERO), false);
    assertEquals(trans.isValidOffset(OFFSET_PONE), false);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T01:00Z to +01:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_ZERO));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #10
Source File: TCKZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #11
Source File: TCKZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void test_London_previousTransition_historic() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransition> trans = test.getTransitions();

    ZoneOffsetTransition first = trans.get(0);
    assertEquals(test.previousTransition(first.getInstant()), null);
    assertEquals(test.previousTransition(first.getInstant().minusNanos(1)), null);

    for (int i = 0; i < trans.size() - 1; i++) {
        ZoneOffsetTransition prev = trans.get(i);
        ZoneOffsetTransition cur = trans.get(i + 1);

        assertEquals(test.previousTransition(cur.getInstant()), prev);
        assertEquals(test.previousTransition(prev.getInstant().plusSeconds(1)), prev);
        assertEquals(test.previousTransition(prev.getInstant().plusNanos(1)), prev);
    }
}
 
Example #12
Source File: TCKZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void test_Apia_jumpForwardOverInternationalDateLine_P12_to_M12() {
    // transition occurred at 1879-07-04T00:00+12:33:04
    ZoneRules test = pacificApia();
    Instant instantBefore = LocalDate.of(1879, 7, 2).atStartOfDay(ZoneOffset.UTC).toInstant();
    ZoneOffsetTransition trans = test.nextTransition(instantBefore);
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(1879, 7, 5, 0, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(1879, 7, 4, 0, 0));
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(+12, 33, 4)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)), true);
    assertEquals(trans.getDuration(), Duration.ofHours(-24));
    assertEquals(trans.getInstant(), LocalDateTime.of(1879, 7, 4, 0, 0).toInstant(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)));

    ZonedDateTime zdt = ZonedDateTime.of(1879, 7, 4, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
    assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(1879, 7, 4, 1, 0, 0));
}
 
Example #13
Source File: TCKZoneRules.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void test_London_nextTransition_rulesBased() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    List<ZoneOffsetTransition> trans = test.getTransitions();

    ZoneOffsetTransition last = trans.get(trans.size() - 1);
    assertEquals(test.nextTransition(last.getInstant()), rules.get(0).createTransition(1998));

    for (int year = 1998; year < 2010; year++) {
        ZoneOffsetTransition a = rules.get(0).createTransition(year);
        ZoneOffsetTransition b = rules.get(1).createTransition(year);
        ZoneOffsetTransition c = rules.get(0).createTransition(year + 1);

        assertEquals(test.nextTransition(a.getInstant()), b);
        assertEquals(test.nextTransition(b.getInstant().minusNanos(1)), b);

        assertEquals(test.nextTransition(b.getInstant()), c);
        assertEquals(test.nextTransition(c.getInstant().minusNanos(1)), c);
    }
}
 
Example #14
Source File: TCKZoneRules.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #15
Source File: TCKZoneRules.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void test_Paris_getStandardOffset() {
    ZoneRules test = europeParis();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21));
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        }
        zdt = zdt.plusMonths(6);
    }
}
 
Example #16
Source File: TCKZoneRulesProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example #17
Source File: TCKZoneRules.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #18
Source File: TCKZoneRules.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_preTimeZones() {
    ZoneRules test = europeLondon();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
    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);
}
 
Example #19
Source File: TCKZoneRules.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_getOffsetInfo_fromDST() {
    ZoneRules test = europeLondon();
    checkOffset(test, createLDT(2008, 10, 24), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 25), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 26), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 27), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 10, 28), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 10, 29), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 10, 30), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 10, 31), OFFSET_ZERO, 1);
    // cutover at 01:00Z
    checkOffset(test, LocalDateTime.of(2008, 10, 26, 0, 59, 59, 999999999), OFFSET_PONE, 1);
    checkOffset(test, LocalDateTime.of(2008, 10, 26, 2, 0, 0, 0), OFFSET_ZERO, 1);
}
 
Example #20
Source File: TCKZoneRules.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_NewYork_getOffsetInfo() {
    ZoneRules test = americaNewYork();
    checkOffset(test, createLDT(2008, 1, 1), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 2, 1), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 3, 1), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 4, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 5, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 6, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 7, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 8, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 9, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 10, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 11, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 12, 1), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 1, 28), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 2, 28), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 3, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 4, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 5, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 6, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 7, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 8, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 9, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 10, 28), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 11, 28), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 12, 28), ZoneOffset.ofHours(-5), 1);
}
 
Example #21
Source File: TCKZoneRules.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_NewYork_getStandardOffset() {
    ZoneRules test = americaNewYork();
    ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC);
    while (dateTime.getYear() < 2010) {
        Instant instant = dateTime.toInstant();
        if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02"));
        } else {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5));
        }
        dateTime = dateTime.plusMonths(6);
    }
}
 
Example #22
Source File: TCKZoneRules.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_nextTransition_historic() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransition> trans = test.getTransitions();

    ZoneOffsetTransition first = trans.get(0);
    assertEquals(test.nextTransition(first.getInstant().minusNanos(1)), first);

    for (int i = 0; i < trans.size() - 1; i++) {
        ZoneOffsetTransition cur = trans.get(i);
        ZoneOffsetTransition next = trans.get(i + 1);

        assertEquals(test.nextTransition(cur.getInstant()), next);
        assertEquals(test.nextTransition(next.getInstant().minusNanos(1)), next);
    }
}
 
Example #23
Source File: TCKZoneRules.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: TCKZoneRules.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_preTimeZones() {
    ZoneRules test = europeLondon();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
    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);
}
 
Example #25
Source File: TestFixedZoneRules.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_data_nullInput() {
    ZoneRules test = make(OFFSET_PONE);
    assertEquals(test.getOffset((Instant) null), OFFSET_PONE);
    assertEquals(test.getOffset((LocalDateTime) null), OFFSET_PONE);
    assertEquals(test.getValidOffsets(null).size(), 1);
    assertEquals(test.getValidOffsets(null).get(0), OFFSET_PONE);
    assertEquals(test.getTransition(null), null);
    assertEquals(test.getStandardOffset(null), OFFSET_PONE);
    assertEquals(test.getDaylightSavings(null), Duration.ZERO);
    assertEquals(test.isDaylightSavings(null), false);
    assertEquals(test.nextTransition(null), null);
    assertEquals(test.previousTransition(null), null);
}
 
Example #26
Source File: TCKZoneRules.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_NewYork_getOffsetInfo_fromDST() {
    ZoneRules test = americaNewYork();
    checkOffset(test, createLDT(2008, 11, 1), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 11, 2), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, createLDT(2008, 11, 3), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 11, 4), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 11, 5), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 11, 6), ZoneOffset.ofHours(-5), 1);
    checkOffset(test, createLDT(2008, 11, 7), ZoneOffset.ofHours(-5), 1);
    // cutover at 02:00 local
    checkOffset(test, LocalDateTime.of(2008, 11, 2, 0, 59, 59, 999999999), ZoneOffset.ofHours(-4), 1);
    checkOffset(test, LocalDateTime.of(2008, 11, 2, 2, 0, 0, 0), ZoneOffset.ofHours(-5), 1);
}
 
Example #27
Source File: TCKZoneRules.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_Paris_getOffsetInfo_fromDST() {
    ZoneRules test = europeParis();
    checkOffset(test, createLDT(2008, 10, 24), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 25), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 26), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 27), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 28), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 29), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 30), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 31), OFFSET_PONE, 1);
    // cutover at 01:00Z which is 02:00+01:00(local Paris time)
    checkOffset(test, LocalDateTime.of(2008, 10, 26, 1, 59, 59, 999999999), OFFSET_PTWO, 1);
    checkOffset(test, LocalDateTime.of(2008, 10, 26, 3, 0, 0, 0), OFFSET_PONE, 1);
}
 
Example #28
Source File: TCKZoneRules.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void test_London_previousTransition_rulesBased() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    List<ZoneOffsetTransition> trans = test.getTransitions();

    ZoneOffsetTransition last = trans.get(trans.size() - 1);
    assertEquals(test.previousTransition(last.getInstant().plusSeconds(1)), last);
    assertEquals(test.previousTransition(last.getInstant().plusNanos(1)), last);

    // Jan 1st of year between transitions and rules
    ZonedDateTime odt = ZonedDateTime.ofInstant(last.getInstant(), last.getOffsetAfter());
    odt = odt.withDayOfYear(1).plusYears(1).with(LocalTime.MIDNIGHT);
    assertEquals(test.previousTransition(odt.toInstant()), last);

    // later years
    for (int year = 1998; year < 2010; year++) {
        ZoneOffsetTransition a = rules.get(0).createTransition(year);
        ZoneOffsetTransition b = rules.get(1).createTransition(year);
        ZoneOffsetTransition c = rules.get(0).createTransition(year + 1);

        assertEquals(test.previousTransition(c.getInstant()), b);
        assertEquals(test.previousTransition(b.getInstant().plusSeconds(1)), b);
        assertEquals(test.previousTransition(b.getInstant().plusNanos(1)), b);

        assertEquals(test.previousTransition(b.getInstant()), a);
        assertEquals(test.previousTransition(a.getInstant().plusSeconds(1)), a);
        assertEquals(test.previousTransition(a.getInstant().plusNanos(1)), a);
    }
}
 
Example #29
Source File: TCKFixedZoneRulesSerialization.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="rules")
public void test_serialization(ZoneRules test, ZoneOffset expectedOffset) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(test);
    baos.close();
    byte[] bytes = baos.toByteArray();

    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream in = new ObjectInputStream(bais);
    ZoneRules result = (ZoneRules) in.readObject();

    assertEquals(result, test);
    assertEquals(result.getClass(), test.getClass());
}
 
Example #30
Source File: TCKZoneRulesProvider.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ZoneRules provideRules(String zoneId, boolean forCaching) {
    count++;
    if (zoneId.equals("DynamicLocation")) {
        return (forCaching ? null : (count > 2 ? ALTERNATE : BASE));
    }
    throw new ZoneRulesException("Invalid");
}