use of android.icu.text.DateTimePatternGenerator in project j2objc by google.
the class DateTimeGeneratorTest method TestEmpty.
@Test
public void TestEmpty() {
// now nothing
DateTimePatternGenerator nullGen = DateTimePatternGenerator.getEmptyInstance();
SimpleDateFormat format = new SimpleDateFormat(nullGen.getBestPattern("yMdHms"), ULocale.ROOT);
TimeZone rootZone = TimeZone.getTimeZone("Etc/GMT");
format.setTimeZone(rootZone);
}
use of android.icu.text.DateTimePatternGenerator in project j2objc by google.
the class DateTimeGeneratorTest method TestBasic.
@Test
public void TestBasic() {
ULocale uLocale = null;
DateTimePatternGenerator dtfg = null;
Date date = null;
for (int i = 0; i < dateTestData.length; ++i) {
if (dateTestData[i] instanceof ULocale) {
uLocale = (ULocale) dateTestData[i];
dtfg = DateTimePatternGenerator.getInstance(uLocale);
if (GENERATE_TEST_DATA)
logln("new ULocale(\"" + uLocale.toString() + "\"),");
} else if (dateTestData[i] instanceof Date) {
date = (Date) dateTestData[i];
if (GENERATE_TEST_DATA)
logln("new Date(" + date.getTime() + "L),");
} else if (dateTestData[i] instanceof String) {
String testSkeleton = (String) dateTestData[i];
String pattern = dtfg.getBestPattern(testSkeleton);
SimpleDateFormat sdf = new SimpleDateFormat(pattern, uLocale);
String formatted = sdf.format(date);
if (GENERATE_TEST_DATA)
logln("new String[] {\"" + testSkeleton + "\", \"" + Utility.escape(formatted) + "\"},");
// logln(uLocale + "\t" + testSkeleton + "\t" + pattern + "\t" + sdf.format(date));
} else {
String[] testPair = (String[]) dateTestData[i];
String testSkeleton = testPair[0];
String testFormatted = testPair[1];
String pattern = dtfg.getBestPattern(testSkeleton);
SimpleDateFormat sdf = new SimpleDateFormat(pattern, uLocale);
String formatted = sdf.format(date);
if (GENERATE_TEST_DATA) {
logln("new String[] {\"" + testSkeleton + "\", \"" + Utility.escape(formatted) + "\"},");
} else if (!formatted.equals(testFormatted)) {
errln(uLocale + "\tformatted string doesn't match test case: " + testSkeleton + "\t generated: " + pattern + "\t expected: " + testFormatted + "\t got: " + formatted);
if (true) {
// debug
pattern = dtfg.getBestPattern(testSkeleton);
sdf = new SimpleDateFormat(pattern, uLocale);
formatted = sdf.format(date);
}
}
// logln(uLocale + "\t" + testSkeleton + "\t" + pattern + "\t" + sdf.format(date));
}
}
}
use of android.icu.text.DateTimePatternGenerator in project j2objc by google.
the class DateTimeGeneratorTest method TestGetAppendItemFormat.
/* Tests the method
* public String getAppendItemFormat(int field)
*/
@Test
public void TestGetAppendItemFormat() {
DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance(ULocale.ENGLISH);
int[] fields = { DateTimePatternGenerator.ERA, DateTimePatternGenerator.DAY, DateTimePatternGenerator.SECOND };
String[] results = { "{0} {1}", "{0} ({2}: {1})", "{0} ({2}: {1})" };
for (int i = 0; i < fields.length; i++) {
if (!dtpg.getAppendItemFormat(fields[i]).equals(results[i])) {
errln("DateTimePatternGenerator.getAppendItemFormat(int field) " + "did not return as expected. For field " + fields[i] + ", was expecting " + results[i] + " but got back " + dtpg.getAppendItemFormat(fields[i]));
}
}
}
use of android.icu.text.DateTimePatternGenerator in project j2objc by google.
the class DateTimeGeneratorTest method TestT7169.
/*
* Test case for DateFormatPatternGenerator threading problem #7169
*/
@Test
public void TestT7169() {
Thread[] workers = new Thread[10];
for (int i = 0; i < workers.length; i++) {
workers[i] = new Thread(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < 50; i++) {
DateTimePatternGenerator patternGenerator = DateTimePatternGenerator.getFrozenInstance(ULocale.US);
patternGenerator.getBestPattern("MMMMd");
}
} catch (Exception e) {
errln("FAIL: Caught an exception (frozen)" + e);
}
try {
for (int i = 0; i < 50; i++) {
DateTimePatternGenerator patternGenerator = DateTimePatternGenerator.getInstance(ULocale.US);
patternGenerator.getBestPattern("MMMMd");
}
} catch (Exception e) {
errln("FAIL: Caught an exception " + e);
}
}
});
}
for (Thread wk : workers) {
wk.start();
}
for (Thread wk : workers) {
try {
wk.join();
} catch (InterruptedException ie) {
}
}
}
use of android.icu.text.DateTimePatternGenerator in project j2objc by google.
the class DateTimeGeneratorTest method TestRoot.
@Test
public void TestRoot() {
DateTimePatternGenerator rootGen = DateTimePatternGenerator.getInstance(ULocale.ROOT);
SimpleDateFormat rootFormat = new SimpleDateFormat(rootGen.getBestPattern("yMdHms"), ULocale.ROOT);
rootFormat.setTimeZone(gmt);
// *** expected result should be "1999-10-14 6:58:59" with current data, changed test temporarily to match current result, needs investigation
assertEquals("root format: yMdHms", "1999-10-14 06:58:59", rootFormat.format(sampleDate));
}
Aggregations