Skip to content

Commit 47a2848

Browse files
authored
CLDR-18916 Unexpected date formats (#5007)
1 parent 5b359b5 commit 47a2848

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.unicode.cldr.tool;
2+
3+
import com.google.common.base.Joiner;
4+
import com.ibm.icu.impl.CalType;
5+
import java.io.IOException;
6+
import java.util.Map;
7+
import java.util.Set;
8+
import java.util.TreeMap;
9+
import java.util.TreeSet;
10+
import org.unicode.cldr.util.CLDRFile;
11+
import org.unicode.cldr.util.CLDRPaths;
12+
import org.unicode.cldr.util.CLDRTool;
13+
import org.unicode.cldr.util.Factory;
14+
15+
@CLDRTool(alias = "unexpected", description = "Show unexpected date formats")
16+
public class ShowUnexpectedDateFormats {
17+
private static final String[] formats = {
18+
"MMMEEEEd",
19+
"MMMMEEEEd",
20+
"yMMMEEEEd",
21+
"yMMMMEEEEd",
22+
"GyMMMEEEEd/d",
23+
"GyMMMEEEEd/G",
24+
"GyMMMEEEEd/M",
25+
"GyMMMEEEEd/y"
26+
};
27+
28+
public static void main(String[] args) throws IOException {
29+
Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*");
30+
Set<String> locales = new TreeSet<>(cldrFactory.getAvailable());
31+
System.out.println("Checking " + locales.size() + " locales");
32+
Map<String, Integer> count = new TreeMap<>();
33+
Set<String> localesWithUnexpectedPaths = new TreeSet<>();
34+
for (String loc : locales) {
35+
CLDRFile cldrFile = cldrFactory.make(loc, false);
36+
for (String format : formats) {
37+
for (CalType calType : CalType.values()) {
38+
String path = makePathFromFormat(calType, format);
39+
String value = cldrFile.getStringValue(path);
40+
if (value != null) {
41+
System.out.println(loc + "\t" + path + "\t" + value);
42+
localesWithUnexpectedPaths.add(loc);
43+
Integer c = count.get(format);
44+
if (c == null) {
45+
c = 0;
46+
}
47+
count.put(format, c + 1);
48+
}
49+
}
50+
}
51+
}
52+
for (String format : formats) {
53+
Integer c = count.get(format);
54+
if (c == null) {
55+
c = 0;
56+
}
57+
System.out.println(format + "\t" + c);
58+
}
59+
System.out.println(
60+
localesWithUnexpectedPaths.size()
61+
+ " locales with unexpected paths: "
62+
+ Joiner.on(" ").join(localesWithUnexpectedPaths));
63+
}
64+
65+
private static String makePathFromFormat(CalType calType, String format) {
66+
if (format.contains("/")) {
67+
String format1 = format.substring(0, format.length() - 2);
68+
String format2 = format.substring(format.length() - 1);
69+
// Note: this path differs from the one below not only in the addition of
70+
// "greatestDifference", but also in having "intervalFormats/intervalFormatItem" instead
71+
// of "availableFormats/dateFormatItem"
72+
return "//ldml/dates/calendars/calendar[@type=\""
73+
+ calType.getId()
74+
+ "\"]/dateTimeFormats/intervalFormats/intervalFormatItem[@id=\""
75+
+ format1
76+
+ "\"]/greatestDifference[@id=\""
77+
+ format2
78+
+ "\"]";
79+
} else {
80+
return "//ldml/dates/calendars/calendar[@type=\""
81+
+ calType.getId()
82+
+ "\"]/dateTimeFormats/availableFormats/dateFormatItem[@id=\""
83+
+ format
84+
+ "\"]";
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)