use of android.icu.text.DateFormatSymbols in project j2objc by google.
the class IBMCalendarTest method TestSimpleDateFormatCoverage.
public void TestSimpleDateFormatCoverage() {
class StubSimpleDateFormat extends SimpleDateFormat {
private static final long serialVersionUID = 1L;
public StubSimpleDateFormat(String pattern, Locale loc) {
new SimpleDateFormat(pattern, loc);
}
public void run() {
Calendar cal = Calendar.getInstance(Locale.US);
cal.clear();
// Sat 15:00
cal.set(2000, Calendar.MARCH, 18, 15, 0, 1);
DateFormatSymbols theseSymbols = this.getSymbols();
String shouldBeMonday = theseSymbols.getWeekdays()[Calendar.MONDAY];
assertEquals("Should be Monday", "Monday", shouldBeMonday);
String[] matchData = { "16", "2016", "2016AD", "Monday", "lunes" };
int matchIndex = matchString("Monday March 28, 2016", 0, Calendar.DAY_OF_WEEK, matchData, cal);
// Position of the pointer after the matched string.
assertEquals("matchData for Monday", 6, matchIndex);
matchIndex = matchString("Monday March 28, 2016 AD", 17, Calendar.YEAR, matchData, cal);
// Position of the pointer after the matched string.
assertEquals("matchData for 2016", 21, matchIndex);
char ch = 'y';
int count = 4;
int beginOffset = 0;
// Reset this
cal.set(Calendar.YEAR, 2000);
assertEquals("calendar year reset", 2000, cal.get(Calendar.YEAR));
FieldPosition pos = new FieldPosition(java.text.DateFormat.YEAR_FIELD);
String subFormatResult = subFormat(ch, count, beginOffset, pos, theseSymbols, cal);
assertEquals("subFormat result", "2000", subFormatResult);
String testParseString = "some text with a date 2017-03-15";
int start = 22;
boolean obeyCount = true;
boolean allowNegative = false;
boolean[] ambiguousYear = { true, false, true };
int subParseResult = subParse(testParseString, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);
assertEquals("subParseResult result", 26, subParseResult);
assertEquals("parsed year", 2017, cal.get(Calendar.YEAR));
}
}
StubSimpleDateFormat stub = new StubSimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS", Locale.US);
stub.run();
}
use of android.icu.text.DateFormatSymbols in project j2objc by google.
the class DateFormatMiscTests method Test4117335.
/*
* @bug 4117335
*/
@Test
public void Test4117335() {
final String bc = "\u7D00\u5143\u524D";
final String ad = "\u897f\u66a6";
final String jstLong = "\u65e5\u672c\u6a19\u6e96\u6642";
final String jdtLong = "\u65e5\u672c\u590f\u6642\u9593";
final String jstShort = "JST";
final String jdtShort = "JDT";
final String tzID = "Asia/Tokyo";
DateFormatSymbols symbols = new DateFormatSymbols(Locale.JAPAN);
final String[] eras = symbols.getEraNames();
assertEquals("BC =", bc, eras[0]);
assertEquals("AD =", ad, eras[1]);
// don't use hard-coded index!
final String[][] zones = symbols.getZoneStrings();
int index = -1;
for (int i = 0; i < zones.length; ++i) {
if (tzID.equals(zones[i][0])) {
index = i;
break;
}
}
if (index == -1) {
errln("could not find " + tzID);
} else {
assertEquals("Long zone name = ", jstLong, zones[index][1]);
assertEquals("Short zone name = ", jstShort, zones[index][2]);
assertEquals("Long zone name (3) = ", jdtLong, zones[index][3]);
assertEquals("Short zone name (4) = ", jdtShort, zones[index][4]);
}
}
use of android.icu.text.DateFormatSymbols in project j2objc by google.
the class DateFormatRegressionTestJ method Test4103926.
// Return value of getAmPmStrings
@Test
public void Test4103926() {
String[] act_Ampms;
String[] exp_Ampms = { "AM", "PM" };
Locale.setDefault(Locale.US);
DateFormatSymbols dfs = new DateFormatSymbols();
act_Ampms = dfs.getAmPmStrings();
if (act_Ampms.length != exp_Ampms.length) {
errln("The result is not expected!");
} else {
for (int i = 0; i < act_Ampms.length; i++) {
if (!act_Ampms[i].equals(exp_Ampms[i]))
errln("The result is not expected!");
}
}
}
use of android.icu.text.DateFormatSymbols in project j2objc by google.
the class DateFormatTest method TestCalendarType.
/*
* Test for checking SimpleDateFormat/DateFormatSymbols creation
* honor the calendar keyword in the given locale. See ticket#6100
*/
@Test
public void TestCalendarType() {
final String testPattern = "GGGG y MMMM d EEEE";
final ULocale[] testLocales = { new ULocale("de"), new ULocale("fr_FR@calendar=gregorian"), new ULocale("en@calendar=islamic"), new ULocale("ja_JP@calendar=japanese"), new ULocale("zh_Hans_CN@calendar=bogus"), new ULocale("ko_KR@calendar=dangi") };
SimpleDateFormat[] formatters = new SimpleDateFormat[5];
for (int i = 0; i < testLocales.length; i++) {
// Create a locale with no keywords
StringBuffer locStrBuf = new StringBuffer();
if (testLocales[i].getLanguage().length() > 0) {
locStrBuf.append(testLocales[i].getLanguage());
}
if (testLocales[i].getScript().length() > 0) {
locStrBuf.append('_');
locStrBuf.append(testLocales[i].getScript());
}
if (testLocales[i].getCountry().length() > 0) {
locStrBuf.append('_');
locStrBuf.append(testLocales[i].getCountry());
}
ULocale locNoKeywords = new ULocale(locStrBuf.toString());
Calendar cal = Calendar.getInstance(testLocales[i]);
// Calendar getDateFormat method
DateFormat df = cal.getDateTimeFormat(DateFormat.MEDIUM, DateFormat.MEDIUM, locNoKeywords);
if (df instanceof SimpleDateFormat) {
formatters[0] = (SimpleDateFormat) df;
formatters[0].applyPattern(testPattern);
} else {
formatters[0] = null;
}
// DateFormat constructor with locale
df = DateFormat.getDateInstance(DateFormat.MEDIUM, testLocales[i]);
if (df instanceof SimpleDateFormat) {
formatters[1] = (SimpleDateFormat) df;
formatters[1].applyPattern(testPattern);
} else {
formatters[1] = null;
}
// DateFormat constructor with Calendar
df = DateFormat.getDateInstance(cal, DateFormat.MEDIUM, locNoKeywords);
if (df instanceof SimpleDateFormat) {
formatters[2] = (SimpleDateFormat) df;
formatters[2].applyPattern(testPattern);
} else {
formatters[2] = null;
}
// SimpleDateFormat constructor
formatters[3] = new SimpleDateFormat(testPattern, testLocales[i]);
// SimpleDateFormat with DateFormatSymbols
DateFormatSymbols dfs = new DateFormatSymbols(testLocales[i]);
formatters[4] = new SimpleDateFormat(testPattern, dfs, testLocales[i]);
// All SimpleDateFormat instances should produce the exact
// same result.
String expected = null;
Date d = new Date();
for (int j = 0; j < formatters.length; j++) {
if (formatters[j] != null) {
String tmp = formatters[j].format(d);
if (expected == null) {
expected = tmp;
} else if (!expected.equals(tmp)) {
errln("FAIL: formatter[" + j + "] returned \"" + tmp + "\" in locale " + testLocales[i] + " - expected: " + expected);
}
}
}
}
}
use of android.icu.text.DateFormatSymbols in project j2objc by google.
the class IntlTestDateFormatSymbols method TestGetEraNames.
@Test
public void TestGetEraNames() {
DateFormatSymbols symbol;
symbol = new DateFormatSymbols(Locale.getDefault());
String[] s = symbol.getEraNames();
for (int i = 0; i < s.length; i++) {
logln(s[i]);
}
}
Aggregations