diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index 6ae456a0e..cb04ca2c8 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -556,13 +556,8 @@ public class TString extends TObject implements TSerializable, TComparable>> 28); - hashCode ^= 347236277 ^ c; - if (hashCode == 0) { - ++hashCode; - } + hashCode = 31 * hashCode + c; } } return hashCode; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java index 5fe447809..ce80ccb3c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java @@ -48,6 +48,7 @@ public class DateNativeGenerator implements Generator, DependencyPlugin { case "getHours": case "getMinutes": case "getSeconds": + case "getTimezoneOffset": generateGetMethod(context, writer, methodRef.getName()); break; case "setFullYear": diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java index 5fdd0a53b..50ba9f5b0 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java @@ -166,8 +166,8 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl String country = locale.getCountry(); if (country.isEmpty()) { String subtags = CLDRHelper.getLikelySubtags(locale.getLanguage()); - int index = subtags.lastIndexOf('-'); - country = index > 0 ? subtags.substring(subtags.lastIndexOf('-') + 1) : ""; + int index = subtags.lastIndexOf('_'); + country = index > 0 ? subtags.substring(index + 1) : ""; } return country; } 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 8d9ede9d3..4e33d9c5a 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java +++ b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java @@ -15,6 +15,7 @@ */ package org.teavm.samples; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; @@ -36,12 +37,15 @@ 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 HTMLSelectElement fieldElem = (HTMLSelectElement)document.getElementById("field"); + private static Date currentDate = new Date(); private static Locale[] locales; private static Locale currentLocale; + private static int currentField; public static void main(String[] args) { fillLocales(); + bindFieldEvent(); window.setInterval(new TimerHandler() { @Override public void onTimer() { @@ -49,6 +53,7 @@ public class DateTime { } }, 250); updateCurrentLocale(); + updateCurrentField(); } private static void fillLocales() { @@ -67,6 +72,14 @@ public class DateTime { }); } + private static void bindFieldEvent() { + fieldElem.addEventListener("change", new EventListener() { + @Override public void handleEvent(Event evt) { + updateCurrentField(); + } + }); + } + private static void updateCurrentLocale() { currentLocale = locales[localeElem.getSelectedIndex()]; GregorianCalendar calendar = new GregorianCalendar(currentLocale); @@ -83,10 +96,66 @@ public class DateTime { private static void setCurrentTime(Date date) { currentDate = date; updateCurrentTimeText(); + updateFieldText(); } private static void updateCurrentTimeText() { HTMLInputElement timeElem = (HTMLInputElement)document.getElementById("current-time"); timeElem.setValue(currentDate.toString()); } + + private static void updateCurrentField() { + switch (fieldElem.getValue()) { + case "era": + currentField = Calendar.ERA; + break; + case "year": + currentField = Calendar.YEAR; + break; + case "month": + currentField = Calendar.MONTH; + break; + case "week-of-year": + currentField = Calendar.WEEK_OF_YEAR; + break; + case "week-of-month": + currentField = Calendar.WEEK_OF_MONTH; + break; + case "date": + currentField = Calendar.DATE; + break; + case "day-of-year": + currentField = Calendar.DAY_OF_YEAR; + break; + case "day-of-week": + currentField = Calendar.DAY_OF_WEEK; + break; + case "am-pm": + currentField = Calendar.AM_PM; + break; + case "hour": + currentField = Calendar.HOUR; + break; + case "hour-of-day": + currentField = Calendar.HOUR_OF_DAY; + break; + case "minute": + currentField = Calendar.MINUTE; + break; + case "second": + currentField = Calendar.SECOND; + break; + case "zone-offset": + currentField = Calendar.ZONE_OFFSET; + break; + } + updateFieldText(); + } + + private static void updateFieldText() { + HTMLInputElement fieldValueElem = (HTMLInputElement)document.getElementById("field-value"); + Calendar calendar = new GregorianCalendar(currentLocale); + calendar.setTime(currentDate); + fieldValueElem.setValue(String.valueOf(calendar.get(currentField))); + } }