Fix how weeks are represented in DateFormatSymbols

Add missing methods to DateFormatSymbols
This commit is contained in:
Alexey Andreev 2021-03-17 10:13:38 +03:00
parent 6c75ce7f68
commit 26db1acc96
2 changed files with 18 additions and 4 deletions

View File

@ -46,6 +46,9 @@ abstract class TDateFormatElement {
static int whichMatches(String text, TParsePosition position, String[] patterns) { static int whichMatches(String text, TParsePosition position, String[] patterns) {
for (int i = 0; i < patterns.length; ++i) { for (int i = 0; i < patterns.length; ++i) {
if (patterns[i] == null) {
continue;
}
if (matches(text, position.getIndex(), patterns[i])) { if (matches(text, position.getIndex(), patterns[i])) {
position.setIndex(position.getIndex() + patterns[i].length()); position.setIndex(position.getIndex() + patterns[i].length());
return i; return i;
@ -117,7 +120,7 @@ abstract class TDateFormatElement {
@Override @Override
public void format(TCalendar date, StringBuffer buffer) { 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]); buffer.append(abbreviated ? shortWeeks[weekday] : weeks[weekday]);
} }

View File

@ -33,7 +33,6 @@ public class TDateFormatSymbols implements TSerializable, TCloneable {
String[] weekdays; String[] weekdays;
String[][] zoneStrings; String[][] zoneStrings;
public TDateFormatSymbols() { public TDateFormatSymbols() {
this(TLocale.getDefault()); this(TLocale.getDefault());
} }
@ -146,14 +145,22 @@ public class TDateFormatSymbols implements TSerializable, TCloneable {
public String[] getShortWeekdays() { public String[] getShortWeekdays() {
if (shortWeekdays == null) { 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(); return shortWeekdays.clone();
} }
public String[] getWeekdays() { public String[] getWeekdays() {
if (weekdays == null) { 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(); return weekdays.clone();
} }
@ -235,4 +242,8 @@ public class TDateFormatSymbols implements TSerializable, TCloneable {
public void setZoneStrings(String[][] data) { public void setZoneStrings(String[][] data) {
zoneStrings = data.clone(); zoneStrings = data.clone();
} }
public static TDateFormatSymbols getInstance(TLocale locale) {
return new TDateFormatSymbols(locale);
}
} }