use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class DateFormatRegressionTest method Test4134203.
/**
* @bug 4134203
* SimpleDateFormat won't parse "GMT"
*/
@Test
public void Test4134203() {
String dateFormat = "MM/dd/yy HH:mm:ss zzz";
SimpleDateFormat fmt = new SimpleDateFormat(dateFormat);
ParsePosition p0 = new ParsePosition(0);
Date d = fmt.parse("01/22/92 04:52:00 GMT", p0);
logln(d.toString());
if (p0.equals(new ParsePosition(0)))
errln("Fail: failed to parse 'GMT'");
// In the failure case an exception is thrown by parse();
// if no exception is thrown, the test passes.
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class DateFormatRegressionTest method Test4103341.
/**
* @bug 4103341
*/
@Test
public void Test4103341() {
TimeZone saveZone = TimeZone.getDefault();
try {
// {sfb} changed from adoptDefault to setDefault
TimeZone.setDefault(TimeZone.getTimeZone("CST"));
SimpleDateFormat simple = new SimpleDateFormat("MM/dd/yyyy HH:mm");
TimeZone temp = TimeZone.getDefault();
if (!simple.getTimeZone().equals(temp))
errln("Fail: SimpleDateFormat not using default zone");
} finally {
TimeZone.setDefault(saveZone);
}
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class DateFormatRegressionTest method TestT10110.
@Test
public void TestT10110() {
try {
SimpleDateFormat formatter = new SimpleDateFormat("Gy年M月d日E", new Locale("zh_Hans"));
/* Object parsed = */
formatter.parseObject("610000");
} catch (ParseException pe) {
return;
} catch (Throwable t) {
errln("ParseException not thrown for bad pattern! exception was: " + t.getLocalizedMessage());
return;
}
errln("No exception thrown at all for bad pattern!");
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class DateFormatRegressionTest method TestT10334.
@Test
public void TestT10334() {
String pattern = new String("'--: 'EEE-WW-MMMM-yyyy");
String text = new String("--mon-02-march-2011");
SimpleDateFormat format = new SimpleDateFormat(pattern);
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_PARTIAL_LITERAL_MATCH, false);
try {
format.parse(text);
errln("parse partial match did NOT fail in strict mode!");
} catch (ParseException pe) {
// expected
}
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_PARTIAL_LITERAL_MATCH, true);
try {
format.parse(text);
} catch (ParseException pe) {
errln("parse partial match failure in lenient mode: " + pe.getLocalizedMessage());
}
pattern = new String("YYYY MM dd");
text = new String("2013 12 10");
format.applyPattern(pattern);
Date referenceDate = null;
try {
referenceDate = format.parse(text);
} catch (ParseException pe) {
errln("unable to instantiate reference date: " + pe.getLocalizedMessage());
}
FieldPosition fp = new FieldPosition(0);
pattern = new String("YYYY LL dd ee cc qq QQ");
format.applyPattern(pattern);
StringBuffer formattedString = new StringBuffer();
formattedString = format.format(referenceDate, formattedString, fp);
logln("ref date: " + formattedString);
pattern = new String("YYYY LLL dd eee ccc qqq QQQ");
text = new String("2013 12 10 03 3 04 04");
format.applyPattern(pattern);
logln(format.format(referenceDate));
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_ALLOW_NUMERIC, true);
ParsePosition pp = new ParsePosition(0);
format.parse(text, pp);
int errorIdx = pp.getErrorIndex();
if (errorIdx != -1) {
errln("numeric parse error at[" + errorIdx + "] on char[" + pattern.substring(errorIdx, errorIdx + 1) + "] in pattern[" + pattern + "]");
}
format.setBooleanAttribute(DateFormat.BooleanAttribute.PARSE_ALLOW_NUMERIC, false);
try {
format.parse(text);
errln("numeric parse did NOT fail in strict mode!");
} catch (ParseException pe) {
// expected
}
/*
* test to verify new code (and improve code coverage) for normal quarter processing
*/
text = new String("2013 Dec 10 Thu Thu Q4 Q4");
try {
format.parse(text);
} catch (ParseException pe) {
errln("normal quarter processing failed");
}
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class DateFormatRoundTripTest method TestDateFormatRoundTrip.
// TODO: test is randomly failing depending on the randomly generated date
@Test
public void TestDateFormatRoundTrip() {
dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
getFieldCal = Calendar.getInstance();
// use test framework's random seed
ran = createRandom();
final Locale[] avail = DateFormat.getAvailableLocales();
int locCount = avail.length;
logln("DateFormat available locales: " + locCount);
if (quick) {
if (locCount > 5)
locCount = 5;
logln("Quick mode: only testing first 5 Locales");
}
TimeZone tz = TimeZone.getDefault();
logln("Default TimeZone: " + tz.getID());
if (INFINITE) {
// Special infinite loop test mode for finding hard to reproduce errors
Locale loc = Locale.getDefault();
logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName());
for (; ; ) {
_test(loc);
}
} else {
_test(Locale.getDefault());
for (int i = 0; i < locCount; ++i) {
_test(avail[i]);
}
}
}
Aggregations