mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Adds short month and short weekday support
This commit is contained in:
parent
8780a13ab3
commit
1443dc2f55
|
@ -57,6 +57,20 @@ public class CLDRHelper {
|
|||
@MetadataProvider(DateSymbolsMetadataGenerator.class)
|
||||
private static native ResourceMap<ResourceArray<StringResource>> getMonthMap();
|
||||
|
||||
public static String[] resolveShortMonths(String language, String country) {
|
||||
return resolveDateFormatSymbols(getShortMonthMap(), language, country);
|
||||
}
|
||||
|
||||
@MetadataProvider(DateSymbolsMetadataGenerator.class)
|
||||
private static native ResourceMap<ResourceArray<StringResource>> getShortMonthMap();
|
||||
|
||||
public static String[] resolveShortWeekdays(String language, String country) {
|
||||
return resolveDateFormatSymbols(getShortWeekdayMap(), language, country);
|
||||
}
|
||||
|
||||
@MetadataProvider(DateSymbolsMetadataGenerator.class)
|
||||
private static native ResourceMap<ResourceArray<StringResource>> getShortWeekdayMap();
|
||||
|
||||
private static String[] resolveDateFormatSymbols(ResourceMap<ResourceArray<StringResource>> map, String language,
|
||||
String country) {
|
||||
String localeCode = getCode(language, country);
|
||||
|
|
|
@ -30,6 +30,8 @@ public class CLDRLocale {
|
|||
String[] eras;
|
||||
String[] dayPeriods;
|
||||
String[] months;
|
||||
String[] shortMonths;
|
||||
String[] shortWeekdays;
|
||||
|
||||
public Map<String, String> getLanguages() {
|
||||
return Collections.unmodifiableMap(languages);
|
||||
|
@ -50,4 +52,12 @@ public class CLDRLocale {
|
|||
public String[] getMonths() {
|
||||
return Arrays.copyOf(months, months.length);
|
||||
}
|
||||
|
||||
public String[] getShortMonths() {
|
||||
return Arrays.copyOf(shortMonths, shortMonths.length);
|
||||
}
|
||||
|
||||
public String[] getShortWeekdays() {
|
||||
return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.google.gson.JsonParser;
|
|||
* @author Alexey Andreev
|
||||
*/
|
||||
public class CLDRReader {
|
||||
private static String[] weekdayKeys = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
|
||||
private Map<String, CLDRLocale> knownLocales = new LinkedHashMap<>();
|
||||
private Map<String, Integer> minDaysMap = new LinkedHashMap<>();
|
||||
private Map<String, Integer> firstDayMap = new LinkedHashMap<>();
|
||||
|
@ -104,6 +105,8 @@ public class CLDRReader {
|
|||
readEras(localeName, localeInfo, root);
|
||||
readAmPms(localeName, localeInfo, root);
|
||||
readMonths(localeName, localeInfo, root);
|
||||
readShortMonths(localeName, localeInfo, root);
|
||||
readShortWeekdays(localeName, localeInfo, root);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +170,28 @@ public class CLDRReader {
|
|||
}
|
||||
}
|
||||
|
||||
private void readShortMonths(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("months").getAsJsonObject()
|
||||
.get("stand-alone").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 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();
|
||||
locale.shortWeekdays = new String[7];
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
locale.shortWeekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
private void readWeekData(InputStream input) {
|
||||
JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
|
||||
JsonObject weekJson = root.get("supplemental").getAsJsonObject().get("weekData").getAsJsonObject();
|
||||
|
|
|
@ -39,6 +39,14 @@ public class DateSymbolsMetadataGenerator implements MetadataGenerator {
|
|||
return generateSymbols(context, new ResourceExtractor() {
|
||||
@Override public String[] extract(CLDRLocale locale) { return locale.getMonths(); }
|
||||
});
|
||||
case "getShortMonthMap":
|
||||
return generateSymbols(context, new ResourceExtractor() {
|
||||
@Override public String[] extract(CLDRLocale locale) { return locale.getShortMonths(); }
|
||||
});
|
||||
case "getShortWeekdayMap":
|
||||
return generateSymbols(context, new ResourceExtractor() {
|
||||
@Override public String[] extract(CLDRLocale locale) { return locale.getShortWeekdays(); }
|
||||
});
|
||||
default:
|
||||
throw new AssertionError("Unsupported method: " + method);
|
||||
}
|
||||
|
|
|
@ -147,10 +147,16 @@ public class TDateFormatSymbols implements TSerializable, TCloneable {
|
|||
}
|
||||
|
||||
public String[] getShortMonths() {
|
||||
if (shortMonths == null) {
|
||||
shortMonths = CLDRHelper.resolveShortMonths(locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
return shortMonths.clone();
|
||||
}
|
||||
|
||||
public String[] getShortWeekdays() {
|
||||
if (shortWeekdays == null) {
|
||||
shortWeekdays = CLDRHelper.resolveShortWeekdays(locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
return shortWeekdays.clone();
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,10 @@ public class DateTime {
|
|||
text = symbols.getAmPmStrings()[value];
|
||||
break;
|
||||
case Calendar.MONTH:
|
||||
text = symbols.getMonths()[value];
|
||||
text = symbols.getMonths()[value] + "/" + symbols.getShortMonths()[value];
|
||||
break;
|
||||
case Calendar.DAY_OF_WEEK:
|
||||
text = symbols.getShortWeekdays()[value - 1];
|
||||
break;
|
||||
default:
|
||||
text = "";
|
||||
|
|
Loading…
Reference in New Issue
Block a user