From 26db1acc96e6c0e9632e4baf4dc10cb02d9d14f8 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 17 Mar 2021 10:13:38 +0300 Subject: [PATCH] Fix how weeks are represented in DateFormatSymbols Add missing methods to DateFormatSymbols --- .../classlib/java/text/TDateFormatElement.java | 5 ++++- .../classlib/java/text/TDateFormatSymbols.java | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java b/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java index ed7f4e83f..61d2a9de8 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java +++ b/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java @@ -46,6 +46,9 @@ abstract class TDateFormatElement { static int whichMatches(String text, TParsePosition position, String[] patterns) { for (int i = 0; i < patterns.length; ++i) { + if (patterns[i] == null) { + continue; + } if (matches(text, position.getIndex(), patterns[i])) { position.setIndex(position.getIndex() + patterns[i].length()); return i; @@ -117,7 +120,7 @@ abstract class TDateFormatElement { @Override public void format(TCalendar date, StringBuffer buffer) { - int weekday = date.get(TCalendar.DAY_OF_WEEK) - 1; + int weekday = date.get(TCalendar.DAY_OF_WEEK); buffer.append(abbreviated ? shortWeeks[weekday] : weeks[weekday]); } diff --git a/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java b/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java index 9f867f6bd..05ca4f926 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java +++ b/classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java @@ -33,7 +33,6 @@ public class TDateFormatSymbols implements TSerializable, TCloneable { String[] weekdays; String[][] zoneStrings; - public TDateFormatSymbols() { this(TLocale.getDefault()); } @@ -146,14 +145,22 @@ public class TDateFormatSymbols implements TSerializable, TCloneable { public String[] getShortWeekdays() { if (shortWeekdays == null) { - shortWeekdays = CLDRHelper.resolveShortWeekdays(locale.getLanguage(), locale.getCountry()); + shortWeekdays = new String[8]; + String[] cldrWeekdays = CLDRHelper.resolveShortWeekdays(locale.getLanguage(), locale.getCountry()); + for (int i = 0; i < 7; ++i) { + shortWeekdays[i + 1] = cldrWeekdays[i]; + } } return shortWeekdays.clone(); } public String[] getWeekdays() { if (weekdays == null) { - weekdays = CLDRHelper.resolveWeekdays(locale.getLanguage(), locale.getCountry()); + weekdays = new String[8]; + String[] cldrWeekdays = CLDRHelper.resolveWeekdays(locale.getLanguage(), locale.getCountry()); + for (int i = 0; i < 7; ++i) { + weekdays[i + 1] = cldrWeekdays[i]; + } } return weekdays.clone(); } @@ -235,4 +242,8 @@ public class TDateFormatSymbols implements TSerializable, TCloneable { public void setZoneStrings(String[][] data) { zoneStrings = data.clone(); } + + public static TDateFormatSymbols getInstance(TLocale locale) { + return new TDateFormatSymbols(locale); + } }