Example #1
0
  /**
   * {@link IntlAbstractOperations#JDK_TIMEZONE_NAMES}
   *
   * @param tzdataDir the tzdata directory
   * @throws IOException if an I/O error occurs
   */
  static void jdkTimezoneNames(Path tzdataDir) throws IOException {
    Pattern pZone = Pattern.compile("Zone\\s+([a-zA-Z0-9_+\\-/]+)\\s+.*");
    Pattern pLink =
        Pattern.compile("Link\\s+([a-zA-Z0-9_+\\-/]+)\\s+([a-zA-Z0-9_+\\-/]+)(?:\\s+#.*)?");
    Pattern pFileName = Pattern.compile("[a-z0-9]+");

    HashSet<String> ignoreFiles = new HashSet<>(Arrays.asList("backzone"));
    TreeSet<String> names = new TreeSet<>();
    TreeMap<String, String> links = new TreeMap<>();

    try (DirectoryStream<Path> stream = Files.newDirectoryStream(tzdataDir)) {
      for (Path path : stream) {
        String filename = Objects.requireNonNull(path.getFileName()).toString();
        if (pFileName.matcher(filename).matches() && !ignoreFiles.contains(filename)) {
          try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
            for (String line; (line = reader.readLine()) != null; ) {
              if (line.startsWith("Zone")) {
                Matcher m = pZone.matcher(line);
                if (!m.matches()) {
                  System.out.println(line);
                }
                String name = m.group(1);
                boolean changed = names.add(name);
                assert changed : line;
              } else if (line.startsWith("Link")) {
                Matcher m = pLink.matcher(line);
                if (!m.matches()) {
                  System.out.println(line);
                }
                String target = m.group(1);
                String source = m.group(2);
                boolean changed = links.put(source, target) == null;
                assert changed : String.format("%s: %s", filename, line);
              }
            }
          }
        }
      }
    }

    TreeSet<String> allnames = new TreeSet<>();
    allnames.addAll(names);
    for (Map.Entry<String, String> link : links.entrySet()) {
      assert allnames.contains(link.getValue());
      boolean changed = allnames.add(link.getKey());
      assert changed : link;
    }

    TreeSet<String> ids =
        new TreeSet<>(TimeZone.getAvailableIDs(SystemTimeZoneType.ANY, null, null));
    for (String id : new HashSet<>(ids)) {
      if (id.startsWith("SystemV/")) {
        ids.remove(id);
      }
    }

    System.out.println(allnames);
    System.out.println(ids.size());
    System.out.println(allnames.size());

    TreeSet<String> jdkTimeZones = new TreeSet<>(ids);
    jdkTimeZones.removeAll(allnames);
    for (String name : jdkTimeZones) {
      System.out.printf("\"%s\",", name);
    }
  }
 public void testIcuTimezones() throws Exception {
   validateTimezoneIds(com.ibm.icu.util.TimeZone.getAvailableIDs());
 }