1 package org.unicode.cldr.tool; 2 3 import java.util.LinkedHashSet; 4 import java.util.Set; 5 6 import org.unicode.cldr.util.CLDRConfig; 7 import org.unicode.cldr.util.CLDRFile; 8 import org.unicode.cldr.util.DateTimeFormats; 9 import org.unicode.cldr.util.Factory; 10 11 import com.ibm.icu.text.ListFormat; 12 import com.ibm.icu.text.SimpleDateFormat; 13 14 public class GenerateSeedDurations { 15 /* 16 * <numericUnits> 17 * <numericUnit type="ms">mm:ss</numericUnit> <!-- 33:59 --> 18 * <numericUnit type="Hm">HH:mm</numericUnit> <!-- 33:59 --> 19 * <numericUnit type="Hms">HH:mm:ss</numericUnit> <!-- 33:59:59 --> 20 * </numericUnits> 21 * <combinationUnits> 22 * <combinationUnit type="ms">{0}, {1}<combinationUnit> <!-- 3 minutes, 15 seconds --> 23 * <combinationUnit type="Hm">{0}, {1}<combinationUnit> <!-- 3 hours, 15 minutes --> 24 * <combinationUnit type="Hms">{0}, {1}, and {2}<combinationUnit> <!-- 3 hours, 15 minutes, and 25 seconds --> 25 * <combinationUnit type="dH">{0}, {1}<combinationUnit> <!-- 3 days, 15 hours --> 26 * <combinationUnit type="dHm">{0}, {1}, and {2}<combinationUnit> <!-- 3 days, 15 hours, and 35 minutes --> 27 * <combinationUnit type="wd">{0}, {1}<combinationUnit> <!-- 3 weeks, 5 days --> 28 * <combinationUnit type="md">{0}, {1}<combinationUnit> <!-- 3 months, 5 days --> 29 * <combinationUnit type="ym">{0}, {1}<combinationUnit> <!-- 3 years, 11 months --> 30 * <combinationUnit type="ymd">{0}, {1}, and {2}<combinationUnit> <!-- 3 years, 11 months, and 30 days --> 31 * </combinationUnits> 32 */ 33 static CLDRConfig testInfo = ToolConfig.getToolInstance(); 34 static String[] numericUnits = { 35 "ms", "Hm", "Hms" 36 }; 37 static String[] combinationUnits = { 38 "ms", "Hm", "Hms", "dH", "dHm", "wd", "md", "ym", "ymd" 39 }; 40 41 /* 42 * Seed these values using: 43 * for numeric fields, the current time separators 44 * for the others, the current list separators 45 */ 46 public static void main(String[] args) { 47 Factory cldrFactory = testInfo.getCldrFactory(); 48 String[] data = new String[4]; 49 Set<String> warnings = new LinkedHashSet<String>(); 50 for (String locale : cldrFactory.getAvailableLanguages()) { 51 CLDRFile cldrFile = cldrFactory.make(locale, true); 52 String localeString = locale + "\t" + testInfo.getEnglish().getName(locale); 53 System.out.println("\n" + localeString); 54 55 DateTimeFormats formats = new DateTimeFormats().set(cldrFile, "gregorian"); 56 System.out.println(" <numericUnits>"); 57 for (String numericUnit : numericUnits) { 58 SimpleDateFormat pattern = formats.getDateFormatFromSkeleton(numericUnit); 59 String patternString = pattern.toPattern(); 60 if (numericUnit.contains("H")) { 61 if (!patternString.contains("H")) { 62 warnings.add(localeString + "\t" + patternString + "\t ***No 'H'"); 63 } 64 patternString = patternString.replace("HH", "H"); 65 } else { 66 patternString = patternString.replace("mm", "m"); 67 } 68 if (!patternString.contains(":")) { 69 warnings.add(localeString + "\t" + patternString + "\t ***No ':'"); 70 } 71 System.out.println(" <numericUnit type=\"" + numericUnit + "\">" + patternString 72 + "<numericUnit>"); 73 } 74 System.out.println(" </numericUnits>"); 75 76 for (int i = 0; i < ExtractListInfo.paths.length; ++i) { 77 data[i] = cldrFile.getStringValue(ExtractListInfo.paths[i]); 78 } 79 ListFormat listFormat = new ListFormat(data[0], data[1], data[2], data[3]); 80 81 System.out.println(" <combinationUnits>"); 82 for (String combinationUnit : combinationUnits) { 83 String pattern = combinationUnit.length() == 2 84 ? listFormat.format("{0}", "{1}") 85 : listFormat.format("{0}", "{1}", "{2}"); 86 System.out.println(" <combinationUnit type=\"" + combinationUnit + "\">" + pattern 87 + "<combinationUnit>"); 88 } 89 System.out.println(" </combinationUnits>"); 90 } 91 for (String warning : warnings) { 92 System.out.println(warning); 93 } 94 } 95 } 96