Java Code Examples for java.time.ZoneId#getAvailableZoneIds()

The following examples show how to use java.time.ZoneId#getAvailableZoneIds() . 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: TimeZoneRulesImplTest.java    From questdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testPerformance() {
    Set<String> allZones = ZoneId.getAvailableZoneIds();
    List<String> zoneList = new ArrayList<>(allZones);
    Collections.sort(zoneList);
    List<ZoneId> zones = new ArrayList<>(zoneList.size());
    List<TimeZoneRulesImpl> zoneRules = new ArrayList<>(zoneList.size());

    for (String z : zoneList) {
        ZoneId zone = ZoneId.of(z);
        zones.add(zone);
        zoneRules.add(new TimeZoneRulesImpl(zone.getRules()));
    }

    long millis = Timestamps.toMicros(1900, 1, 1, 0, 0);
    long deadline = Timestamps.toMicros(2615, 12, 31, 0, 0);

    while (millis < deadline) {
        for (int i = 0, n = zones.size(); i < n; i++) {
            zoneRules.get(i).getOffset(millis);
        }
        millis += Timestamps.DAY_MICROS;
    }
}
 
Example 2
Source File: DateV4DescriptorSerializerTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testDates() throws StandardException {

    DatabaseContext dc = (DatabaseContext) ContextService.getContext(DatabaseContext.CONTEXT_ID);
    LocaleFinder localeFinder = (dc == null) ? null : dc.getDatabase();
    DescriptorSerializer dateDescriptorSerializer = DateV4DescriptorSerializer.INSTANCE_FACTORY.newInstance();

    try {
        // Encoding/decoding of dates should not be timezone-sensitive.
        for (String zId : ZoneId.getAvailableZoneIds()) {
            ZoneId zoneId = ZoneId.of(zId);
            for (String date : dates)
                testSingleDate(date, localeFinder, zoneId, dateDescriptorSerializer);
        }
    } catch (Exception e) {
        Assert.fail("Exception while testing Date encoding/decoding.");
    }
}
 
Example 3
Source File: TCKZoneId.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 4
Source File: TCKZoneId.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 5
Source File: TCKZoneId.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 6
Source File: TCKZoneId.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 7
Source File: TCKZoneId.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 8
Source File: TCKZoneId.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 9
Source File: TCKZoneOffset.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_ZonedDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (String zoneId : ZoneId.getAvailableZoneIds()) {
        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = ZonedDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneId.of(zoneId));
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());

        OffsetDateTime offsetDateTime_target = zonedDateTime_target.toOffsetDateTime();
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)(base.adjustInto(offsetDateTime_target));
        assertEquals(base, offsetDateTime_result.getOffset());
    }
}
 
Example 10
Source File: TCKZoneOffset.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_ZonedDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (String zoneId : ZoneId.getAvailableZoneIds()) {
        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = ZonedDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneId.of(zoneId));
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());

        OffsetDateTime offsetDateTime_target = zonedDateTime_target.toOffsetDateTime();
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)(base.adjustInto(offsetDateTime_target));
        assertEquals(base, offsetDateTime_result.getOffset());
    }
}
 
Example 11
Source File: TimeZoneRuleFactory.java    From questdb with Apache License 2.0 5 votes vote down vote up
public TimeZoneRuleFactory() {
    int index = 0;
    for (String z : ZoneId.getAvailableZoneIds()) {
        ruleList.add(new TimeZoneRulesImpl(ZoneId.of(z).getRules()));
        ruleMap.put(z, index++);
    }

    for (Map.Entry<String, String> e : ZoneId.SHORT_IDS.entrySet()) {
        String key = e.getKey();
        String alias = e.getValue();

        // key already added somehow?
        int i = ruleMap.get(key);
        if (i == -1) {
            // no, good, add
            i = ruleMap.get(alias);
            if (i == -1) {
                // this could be fixed offset, try parsing value as one
                long offset = Timestamps.parseOffset(alias, 0, alias.length());
                if (offset != Long.MIN_VALUE) {
                    ruleList.add(new FixedTimeZoneRule(Numbers.decodeLowInt(offset) * Timestamps.MILLI_MICROS));
                    ruleMap.put(key, index++);
                }
            } else {
                ruleMap.put(key, i);
            }
        }
    }
}
 
Example 12
Source File: JsonSerializationTest.java    From cqrs-hotel with Apache License 2.0 5 votes vote down vote up
private static Object randomValue(Class<?> type) {
    var random = ThreadLocalRandom.current();
    if (type == UUID.class) {
        return UUID.randomUUID();
    }
    if (type == LocalDate.class) {
        return LocalDate.of(
                random.nextInt(2000, 2100),
                random.nextInt(Month.JANUARY.getValue(), Month.DECEMBER.getValue() + 1),
                random.nextInt(1, Month.FEBRUARY.minLength() + 1));
    }
    if (type == Money.class) {
        return Money.of(
                random.nextDouble(0, 1000),
                pickRandom(Monetary.getCurrencies()));
    }
    if (type == Instant.class) {
        return Instant.ofEpochMilli(random.nextLong());
    }
    if (type == ZonedDateTime.class) {
        var zoneIds = ZoneId.getAvailableZoneIds();
        zoneIds.remove("GMT0"); // XXX: cannot be parsed by java.time.format.DateTimeFormatterBuilder.appendZoneRegionId - fixed in Java 9 https://bugs.openjdk.java.net/browse/JDK-8138664
        var zoneId = ZoneId.of(pickRandom(zoneIds));
        return Instant.ofEpochMilli(random.nextLong()).atZone(zoneId);
    }
    if (type == String.class) {
        return RandomStringUtils.randomAlphanumeric(random.nextInt(10));
    }
    if (type == int.class) {
        return random.nextInt();
    }
    if (type == Class.class) {
        return pickRandom(Arrays.asList(Integer.class, Long.class, Float.class, Double.class));
    }
    throw new IllegalArgumentException("Unsupported type: " + type);
}
 
Example 13
Source File: TCKZoneId.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 14
Source File: TCKZoneOffset.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_ZonedDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (String zoneId : ZoneId.getAvailableZoneIds()) {
        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = ZonedDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneId.of(zoneId));
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());

        OffsetDateTime offsetDateTime_target = zonedDateTime_target.toOffsetDateTime();
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)(base.adjustInto(offsetDateTime_target));
        assertEquals(base, offsetDateTime_result.getOffset());
    }
}
 
Example 15
Source File: TCKZoneOffset.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_ZonedDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (String zoneId : ZoneId.getAvailableZoneIds()) {
        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = ZonedDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneId.of(zoneId));
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());

        OffsetDateTime offsetDateTime_target = zonedDateTime_target.toOffsetDateTime();
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)(base.adjustInto(offsetDateTime_target));
        assertEquals(base, offsetDateTime_result.getOffset());
    }
}
 
Example 16
Source File: TCKZoneId.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 17
Source File: TCKZoneId.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 18
Source File: GetTimeZonesAction.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonResult execute() {
    String tzVersion = ZoneRulesProvider.getVersions("UTC").firstKey();
    Instant now = Instant.now();
    Map<String, Integer> tzOffsets = new TreeMap<>();
    for (String tz : ZoneId.getAvailableZoneIds()) {
        if (!tz.contains("SystemV")) {
            int offset = ZoneId.of(tz).getRules().getOffset(now).getTotalSeconds();
            tzOffsets.put(tz, offset);
        }
    }
    TimeZonesData output = new TimeZonesData(tzVersion, tzOffsets);
    return new JsonResult(output);
}
 
Example 19
Source File: UseZonedDateTimeUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenRequestingZones_thenAtLeastOneIsReturned() {
    Set<String> allZoneIds = ZoneId.getAvailableZoneIds();

    assertThat(allZoneIds.size()).isGreaterThan(1);
}
 
Example 20
Source File: DateTimes.java    From Java-Coding-Problems with MIT License 4 votes vote down vote up
public static List<String> localTimeToAllTimeZones8() {

        List<String> result = new ArrayList<>();
        Set<String> zoneIds = ZoneId.getAvailableZoneIds();

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd'T'HH:mm:ss a Z");

        ZonedDateTime zlt = ZonedDateTime.now();

        zoneIds.forEach((zoneId) -> {
            result.add(zlt.format(formatter) + " in " + zoneId + " is "
                    + zlt.withZoneSameInstant(ZoneId.of(zoneId)).format(formatter));
        });

        return result;
    }