Fixes errors with week data

This commit is contained in:
konsoletyper 2014-05-24 19:48:05 +04:00
parent e83fd18dec
commit 403e4a226e
5 changed files with 31 additions and 10 deletions

View File

@ -47,7 +47,7 @@ public class JCLPlugin implements TeaVMPlugin {
Generator localeGen = new LocaleSettingsNativeGenerator(host.getClassLoader(), host.getProperties());
host.add(new MethodReference("java.util.Locale", "readLanguagesFromCLDR", ValueType.VOID), localeGen);
host.add(new MethodReference("java.util.Locale", "readCountriesFromCLDR", ValueType.VOID), localeGen);
host.add(new MethodReference("java.util.Calendar", "readWeeksFromCLDR", ValueType.VOID), localeGen);
host.add(new MethodReference("java.util.Calendar", "readWeeksFromCDLR", ValueType.VOID), localeGen);
host.add(new MethodReference(CLDRHelper.class.getName(), "readLikelySubtagsFromCLDR", ValueType.VOID),
localeGen);
host.add(new MethodReference("java.util.Locale", "getDefaultLocale", ValueType.object("java.lang.String")),

View File

@ -199,7 +199,7 @@ public class LocaleSettingsNativeGenerator implements Generator {
case "readCountriesFromCLDR":
generateReadCountriesFromCLDR(writer);
break;
case "readWeeksFromCLDR":
case "readWeeksFromCDLR":
generateReadWeeksFromCDLR(writer);
break;
case "readLikelySubtagsFromCLDR":
@ -310,14 +310,14 @@ public class LocaleSettingsNativeGenerator implements Generator {
}
first = false;
writer.append('"').append(Renderer.escapeString(entry.getKey())).append('"').ws().append(':')
.ws().append('"').append(entry.getValue()).append('"');
.ws().append(entry.getValue());
}
writer.outdent().append("};").softNewLine();
}
private void generateReadLikelySubtagsFromCLDR(SourceWriter writer) throws IOException {
generateDefender(writer, "likelySubtags");
writer.append("java.util.Locale").append(".$CLDR.likelySubtags = {").indent().softNewLine();
writer.appendClass("java.util.Locale").append(".$CLDR.likelySubtags = {").indent().softNewLine();
boolean first = true;
for (Map.Entry<String, String> entry : likelySubtags.entrySet()) {
if (!first) {

View File

@ -181,7 +181,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl
return day;
}
@GeneratedBy(LocaleSettingsNativeGenerator.class)
@GeneratedBy(CalendarNativeGenerator.class)
private static native int getFirstDayOfWeek(String localeCode);
private static int resolveMinimalDaysInFirstWeek(TLocale locale) {
@ -193,7 +193,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl
return days;
}
@GeneratedBy(LocaleSettingsNativeGenerator.class)
@GeneratedBy(CalendarNativeGenerator.class)
private static native int getMinimalDaysInFirstWeek(String localeCode);
abstract public void add(int field, int value);

View File

@ -16,6 +16,7 @@
package org.teavm.samples;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import org.teavm.dom.browser.TimerHandler;
import org.teavm.dom.browser.Window;
@ -34,7 +35,10 @@ import org.teavm.jso.JS;
public class DateTime {
private static Window window = (Window)JS.getGlobal();
private static HTMLDocument document = window.getDocument();
private static HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale");
private static Date currentDate;
private static Locale[] locales;
private static Locale currentLocale;
public static void main(String[] args) {
fillLocales();
@ -44,11 +48,12 @@ public class DateTime {
updateCurrentTime();
}
}, 250);
updateCurrentLocale();
}
private static void fillLocales() {
final HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale");
for (Locale locale : Locale.getAvailableLocales()) {
locales = Locale.getAvailableLocales();
for (Locale locale : locales) {
HTMLOptionElement option = (HTMLOptionElement)document.createElement("option");
option.setValue(locale.toString());
option.setLabel(locale.getDisplayName(Locale.getDefault()));
@ -56,11 +61,21 @@ public class DateTime {
}
localeElem.addEventListener("change", new EventListener() {
@Override public void handleEvent(Event evt) {
// Don't do anything
updateCurrentLocale();
updateCurrentTimeText();
}
});
}
private static void updateCurrentLocale() {
currentLocale = locales[localeElem.getSelectedIndex()];
GregorianCalendar calendar = new GregorianCalendar(currentLocale);
HTMLInputElement weekStartElem = (HTMLInputElement)document.getElementById("week-start");
weekStartElem.setValue(String.valueOf(calendar.getFirstDayOfWeek()));
HTMLInputElement weekLengthElem = (HTMLInputElement)document.getElementById("week-length");
weekLengthElem.setValue(String.valueOf(calendar.getMinimalDaysInFirstWeek()));
}
private static void updateCurrentTime() {
setCurrentTime(new Date());
}

View File

@ -13,7 +13,13 @@
</div>
<div>
<label for="current-time">Current time is:</label>
<input type="text" id="current-time" readonly>
<input type="text" id="current-time" readonly size="50">
</div>
<div>
<label for="week-start">Week starts at:</label>
<input type="text" id="week-start" readonly size="5">
<label for="week-length">, first week length is:</label>
<input type="text" id="week-length" readonly size="5">
</div>
<div>
<label for="field">Pick a field:</label>