Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Nov 14, 2024
1 parent ec148c1 commit f91c26f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.time.*;
import java.util.*;
import java.util.ResourceBundle.Control;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -1242,7 +1243,8 @@ private static Stream<String> zidMapEntry() {
private static Stream<String> tzDataLinkEntry() {
try {
return Files.walk(Paths.get(tzDataDir), 1)
.filter(p -> !Files.isDirectory(p))
.filter(p -> p.toFile().isFile())
.filter(p -> p.getFileName().toString().matches("africa|antarctica|asia|australasia|backward|etcetera|europe|northamerica|southamerica"))
.flatMap(CLDRConverter::extractLinks)
.sorted();
} catch (IOException e) {
Expand Down Expand Up @@ -1273,8 +1275,27 @@ private static Stream<String> extractLinks(Path tzFile) {
// Note: the entries are alphabetically sorted, *except* the "world" region
// code, i.e., "001". It should be the last entry for the same windows time
// zone name entries. (cf. TimeZone_md.c)
//
// The default entries from CLDR's windowsZones.xml file can be modified
// with <tzDataDir>/tzmappings.override where mapping overrides
// can be specified.
private static Pattern OVERRIDE_PATTERN = Pattern.compile("(?<win>([^:]+:[^:]+)):(?<java>[^:]+):");
private static void generateWindowsTZMappings() throws Exception {
Files.createDirectories(Paths.get(DESTINATION_DIR, "windows", "conf"));
var override = Path.of(tzDataDir, "tzmappings.override");
if (override.toFile().exists()) {
Files.readAllLines(override).stream()
.map(String::trim)
.filter(o -> !o.isBlank() && !o.startsWith("#"))
.forEach(o -> {
var m = OVERRIDE_PATTERN.matcher(o);
if (m.matches()) {
handlerWinZones.put(m.group("win"), m.group("java"));
} else {
System.out.printf("Unrecognized tzmappings override: %s. Ignored%n", o);
}
});
}
Files.write(Paths.get(DESTINATION_DIR, "windows", "conf", "tzmappings"),
handlerWinZones.keySet().stream()
.filter(k -> k.endsWith(":001") ||
Expand Down
32 changes: 32 additions & 0 deletions src/java.base/share/data/tzdata/tzmappings.override
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# Extra definitions for Windows /lib/tzmappings file. These entries
# replace the existing (Windows Zone Name):(REGION) entries, or are added
# as new entries

# Example entries
# Foo Standard Time:US:America/Los_Angeles:
# Bar Standard Time:001:Asia/Tokyo:

0 comments on commit f91c26f

Please sign in to comment.