diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java index b6abfb854..3dd704716 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java @@ -64,6 +64,13 @@ public class CLDRHelper { @MetadataProvider(DateSymbolsMetadataGenerator.class) private static native ResourceMap> getShortMonthMap(); + public static String[] resolveWeekdays(String language, String country) { + return resolveDateFormatSymbols(getWeekdayMap(), language, country); + } + + @MetadataProvider(DateSymbolsMetadataGenerator.class) + private static native ResourceMap> getWeekdayMap(); + public static String[] resolveShortWeekdays(String language, String country) { return resolveDateFormatSymbols(getShortWeekdayMap(), language, country); } @@ -100,4 +107,38 @@ public class CLDRHelper { @MetadataProvider(FirstDayOfWeekMetadataGenerator.class) public static native ResourceMap getFirstDayOfWeek(); + + public static String resolveNumberFormat(String language, String country) { + return resolveFormatSymbols(getNumberFormatMap(), language, country); + } + + private static native ResourceMap getNumberFormatMap(); + + public static String resolveDecimalFormat(String language, String country) { + return resolveFormatSymbols(getDecimalFormatMap(), language, country); + } + + private static native ResourceMap getDecimalFormatMap(); + + public static String resolvePercentFormat(String language, String country) { + return resolveFormatSymbols(getPercentFormatMap(), language, country); + } + + private static native ResourceMap getPercentFormatMap(); + + private static String resolveFormatSymbols(ResourceMap map, String language, String country) { + String localeCode = getCode(language, country); + StringResource res = map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language) : + map.get("root"); + return res.getValue(); + } + + public static CLDRDecimalData resolveDecimalData(String language, String country) { + ResourceMap map = getDecimalDataMap(); + String localeCode = getCode(language, country); + return map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language) : + map.get("root"); + } + + private static native ResourceMap getDecimalDataMap(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java index 952a3086b..398f6c6b7 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java @@ -31,6 +31,7 @@ public class CLDRLocale { String[] dayPeriods; String[] months; String[] shortMonths; + String[] weekdays; String[] shortWeekdays; public Map getLanguages() { @@ -57,6 +58,10 @@ public class CLDRLocale { return Arrays.copyOf(shortMonths, shortMonths.length); } + public String[] getWeekdays() { + return Arrays.copyOf(weekdays, weekdays.length); + } + public String[] getShortWeekdays() { return Arrays.copyOf(shortWeekdays, shortWeekdays.length); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java index 888808618..f821df429 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java @@ -106,6 +106,7 @@ public class CLDRReader { readAmPms(localeName, localeInfo, root); readMonths(localeName, localeInfo, root); readShortMonths(localeName, localeInfo, root); + readWeekdays(localeName, localeInfo, root); readShortWeekdays(localeName, localeInfo, root); break; } @@ -163,7 +164,7 @@ public class CLDRReader { JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject() .get("dates").getAsJsonObject().get("calendars").getAsJsonObject() .get("gregorian").getAsJsonObject().get("months").getAsJsonObject() - .get("stand-alone").getAsJsonObject().get("wide").getAsJsonObject(); + .get("format").getAsJsonObject().get("wide").getAsJsonObject(); locale.months = new String[12]; for (int i = 0; i < 12; ++i) { locale.months[i] = monthsJson.get(String.valueOf(i + 1)).getAsString(); @@ -174,18 +175,29 @@ public class CLDRReader { JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject() .get("dates").getAsJsonObject().get("calendars").getAsJsonObject() .get("gregorian").getAsJsonObject().get("months").getAsJsonObject() - .get("stand-alone").getAsJsonObject().get("abbreviated").getAsJsonObject(); + .get("format").getAsJsonObject().get("abbreviated").getAsJsonObject(); locale.shortMonths = new String[12]; for (int i = 0; i < 12; ++i) { locale.shortMonths[i] = monthsJson.get(String.valueOf(i + 1)).getAsString(); } } + private void readWeekdays(String localeCode, CLDRLocale locale, JsonObject root) { + JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject() + .get("dates").getAsJsonObject().get("calendars").getAsJsonObject() + .get("gregorian").getAsJsonObject().get("days").getAsJsonObject() + .get("format").getAsJsonObject().get("wide").getAsJsonObject(); + locale.weekdays = new String[7]; + for (int i = 0; i < 7; ++i) { + locale.weekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString(); + } + } + private void readShortWeekdays(String localeCode, CLDRLocale locale, JsonObject root) { JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject() .get("dates").getAsJsonObject().get("calendars").getAsJsonObject() .get("gregorian").getAsJsonObject().get("days").getAsJsonObject() - .get("stand-alone").getAsJsonObject().get("short").getAsJsonObject(); + .get("format").getAsJsonObject().get("short").getAsJsonObject(); locale.shortWeekdays = new String[7]; for (int i = 0; i < 7; ++i) { locale.shortWeekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java index a11f77f73..424c9f9d4 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java @@ -43,6 +43,10 @@ public class DateSymbolsMetadataGenerator implements MetadataGenerator { return generateSymbols(context, new ResourceExtractor() { @Override public String[] extract(CLDRLocale locale) { return locale.getShortMonths(); } }); + case "getWeekdayMap": + return generateSymbols(context, new ResourceExtractor() { + @Override public String[] extract(CLDRLocale locale) { return locale.getWeekdays(); } + }); case "getShortWeekdayMap": return generateSymbols(context, new ResourceExtractor() { @Override public String[] extract(CLDRLocale locale) { return locale.getShortWeekdays(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java index 0e6af286a..3cba349cc 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.teavm.classlib.java.text; import java.util.Arrays; @@ -161,10 +160,16 @@ public class TDateFormatSymbols implements TSerializable, TCloneable { } public String[] getWeekdays() { + if (weekdays == null) { + weekdays = CLDRHelper.resolveWeekdays(locale.getLanguage(), locale.getCountry()); + } return weekdays.clone(); } public String[][] getZoneStrings() { + if (zoneStrings == null) { + return new String[0][]; + } String[][] clone = new String[zoneStrings.length][]; for (int i = zoneStrings.length; --i >= 0;) { clone[i] = zoneStrings[i].clone(); diff --git a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java index 202d3e294..f9f369956 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java +++ b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java @@ -173,7 +173,7 @@ public class DateTime { text = symbols.getMonths()[value] + "/" + symbols.getShortMonths()[value]; break; case Calendar.DAY_OF_WEEK: - text = symbols.getShortWeekdays()[value - 1]; + text = symbols.getWeekdays()[value - 1] + "/" + symbols.getShortWeekdays()[value - 1]; break; default: text = "";