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()); 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", "readLanguagesFromCLDR", ValueType.VOID), localeGen);
host.add(new MethodReference("java.util.Locale", "readCountriesFromCLDR", 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), host.add(new MethodReference(CLDRHelper.class.getName(), "readLikelySubtagsFromCLDR", ValueType.VOID),
localeGen); localeGen);
host.add(new MethodReference("java.util.Locale", "getDefaultLocale", ValueType.object("java.lang.String")), 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": case "readCountriesFromCLDR":
generateReadCountriesFromCLDR(writer); generateReadCountriesFromCLDR(writer);
break; break;
case "readWeeksFromCLDR": case "readWeeksFromCDLR":
generateReadWeeksFromCDLR(writer); generateReadWeeksFromCDLR(writer);
break; break;
case "readLikelySubtagsFromCLDR": case "readLikelySubtagsFromCLDR":
@ -310,14 +310,14 @@ public class LocaleSettingsNativeGenerator implements Generator {
} }
first = false; first = false;
writer.append('"').append(Renderer.escapeString(entry.getKey())).append('"').ws().append(':') writer.append('"').append(Renderer.escapeString(entry.getKey())).append('"').ws().append(':')
.ws().append('"').append(entry.getValue()).append('"'); .ws().append(entry.getValue());
} }
writer.outdent().append("};").softNewLine(); writer.outdent().append("};").softNewLine();
} }
private void generateReadLikelySubtagsFromCLDR(SourceWriter writer) throws IOException { private void generateReadLikelySubtagsFromCLDR(SourceWriter writer) throws IOException {
generateDefender(writer, "likelySubtags"); 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; boolean first = true;
for (Map.Entry<String, String> entry : likelySubtags.entrySet()) { for (Map.Entry<String, String> entry : likelySubtags.entrySet()) {
if (!first) { if (!first) {

View File

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

View File

@ -16,6 +16,7 @@
package org.teavm.samples; package org.teavm.samples;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import org.teavm.dom.browser.TimerHandler; import org.teavm.dom.browser.TimerHandler;
import org.teavm.dom.browser.Window; import org.teavm.dom.browser.Window;
@ -34,7 +35,10 @@ import org.teavm.jso.JS;
public class DateTime { public class DateTime {
private static Window window = (Window)JS.getGlobal(); private static Window window = (Window)JS.getGlobal();
private static HTMLDocument document = window.getDocument(); private static HTMLDocument document = window.getDocument();
private static HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale");
private static Date currentDate; private static Date currentDate;
private static Locale[] locales;
private static Locale currentLocale;
public static void main(String[] args) { public static void main(String[] args) {
fillLocales(); fillLocales();
@ -44,11 +48,12 @@ public class DateTime {
updateCurrentTime(); updateCurrentTime();
} }
}, 250); }, 250);
updateCurrentLocale();
} }
private static void fillLocales() { private static void fillLocales() {
final HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale"); locales = Locale.getAvailableLocales();
for (Locale locale : Locale.getAvailableLocales()) { for (Locale locale : locales) {
HTMLOptionElement option = (HTMLOptionElement)document.createElement("option"); HTMLOptionElement option = (HTMLOptionElement)document.createElement("option");
option.setValue(locale.toString()); option.setValue(locale.toString());
option.setLabel(locale.getDisplayName(Locale.getDefault())); option.setLabel(locale.getDisplayName(Locale.getDefault()));
@ -56,11 +61,21 @@ public class DateTime {
} }
localeElem.addEventListener("change", new EventListener() { localeElem.addEventListener("change", new EventListener() {
@Override public void handleEvent(Event evt) { @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() { private static void updateCurrentTime() {
setCurrentTime(new Date()); setCurrentTime(new Date());
} }

View File

@ -13,7 +13,13 @@
</div> </div>
<div> <div>
<label for="current-time">Current time is:</label> <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>
<div> <div>
<label for="field">Pick a field:</label> <label for="field">Pick a field:</label>