use of android.icu.text.DateFormat in project j2objc by google.
the class DateFormatRegressionTest method TestDangiFormat.
// Date formatting with Dangi calendar in en locale (#9987)
@Test
public void TestDangiFormat() {
DateFormat fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, new ULocale("en@calendar=dangi"));
String calType = fmt.getCalendar().getType();
assertEquals("Incorrect calendar type used by the date format instance", "dangi", calType);
GregorianCalendar gcal = new GregorianCalendar();
gcal.set(2013, Calendar.MARCH, 1, 0, 0, 0);
Date d = gcal.getTime();
String dangiDateStr = fmt.format(d);
assertEquals("Bad date format", "Mo1 20, 2013", dangiDateStr);
}
use of android.icu.text.DateFormat in project j2objc by google.
the class DateFormatRegressionTest method Test4052408.
/**
* @bug 4052408
*/
@Test
public void Test4052408() {
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(97 + 1900, Calendar.MAY, 3, 8, 55);
Date dt = cal.getTime();
String str = fmt.format(dt);
logln(str);
if (!str.equals("5/3/97, 8:55 AM"))
errln("Fail: Test broken; Want 5/3/97, 8:55 AM Got " + str);
String[] expected = { // "ERA_FIELD",
"", // "YEAR_FIELD",
"97", // "MONTH_FIELD",
"5", // "DATE_FIELD",
"3", // "HOUR_OF_DAY1_FIELD",
"", // "HOUR_OF_DAY0_FIELD",
"", // "MINUTE_FIELD",
"55", // "SECOND_FIELD",
"", // "MILLISECOND_FIELD",
"", // "DAY_OF_WEEK_FIELD",
"", // "DAY_OF_YEAR_FIELD",
"", // "DAY_OF_WEEK_IN_MONTH_FIELD",
"", // "WEEK_OF_YEAR_FIELD",
"", // "WEEK_OF_MONTH_FIELD",
"", // "AM_PM_FIELD",
"AM", // "HOUR1_FIELD",
"8", // "HOUR0_FIELD",
"", // "TIMEZONE_FIELD"
"" };
String[] fieldNames = { "ERA_FIELD", "YEAR_FIELD", "MONTH_FIELD", "DATE_FIELD", "HOUR_OF_DAY1_FIELD", "HOUR_OF_DAY0_FIELD", "MINUTE_FIELD", "SECOND_FIELD", "MILLISECOND_FIELD", "DAY_OF_WEEK_FIELD", "DAY_OF_YEAR_FIELD", "DAY_OF_WEEK_IN_MONTH_FIELD", "WEEK_OF_YEAR_FIELD", "WEEK_OF_MONTH_FIELD", "AM_PM_FIELD", "HOUR1_FIELD", "HOUR0_FIELD", "TIMEZONE_FIELD" };
boolean pass = true;
for (int i = 0; i <= 17; ++i) {
FieldPosition pos = new FieldPosition(i);
StringBuffer buf = new StringBuffer("");
fmt.format(dt, buf, pos);
// char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()];
String dst = buf.substring(pos.getBeginIndex(), pos.getEndIndex());
str = dst;
log(i + ": " + fieldNames[i] + ", \"" + str + "\", " + pos.getBeginIndex() + ", " + pos.getEndIndex());
String exp = expected[i];
if ((exp.length() == 0 && str.length() == 0) || str.equals(exp))
logln(" ok");
else {
logln(" expected " + exp);
pass = false;
}
}
if (!pass)
errln("Fail: FieldPosition not set right by DateFormat");
}
use of android.icu.text.DateFormat in project j2objc by google.
the class DateFormatRegressionTest method TestT5683.
// Ticket#5683
// Some ICU4J 3.6 data files contain garbage data which prevent the code to resolve another
// bundle as an alias. zh_TW should be equivalent to zh_Hant_TW
@Test
public void TestT5683() {
Locale[] aliasLocales = { new Locale("zh", "CN"), new Locale("zh", "TW"), new Locale("zh", "HK"), new Locale("zh", "SG"), new Locale("zh", "MO") };
ULocale[] canonicalLocales = { new ULocale("zh_Hans_CN"), new ULocale("zh_Hant_TW"), new ULocale("zh_Hant_HK"), new ULocale("zh_Hans_SG"), new ULocale("zh_Hant_MO") };
Date d = new Date(0);
for (int i = 0; i < aliasLocales.length; i++) {
DateFormat dfAlias = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, aliasLocales[i]);
DateFormat dfCanonical = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, canonicalLocales[i]);
String sAlias = dfAlias.format(d);
String sCanonical = dfCanonical.format(d);
if (!sAlias.equals(sCanonical)) {
errln("Fail: The format result for locale " + aliasLocales[i] + " is different from the result for locale " + canonicalLocales[i] + ": " + sAlias + "[" + aliasLocales[i] + "] / " + sCanonical + "[" + canonicalLocales[i] + "]");
}
}
}
use of android.icu.text.DateFormat in project j2objc by google.
the class DateFormatRegressionTest method Test714.
@Test
public void Test714() {
// TimeZone Offset
TimeZone defaultTZ = TimeZone.getDefault();
TimeZone PST = TimeZone.getTimeZone("PST");
int defaultOffset = defaultTZ.getRawOffset();
int PSTOffset = PST.getRawOffset();
Date d = new Date(978103543000l - (defaultOffset - PSTOffset));
d = new Date(d.getTime() - (defaultTZ.inDaylightTime(d) ? 3600000 : 0));
DateFormat fmt = DateFormat.getDateTimeInstance(-1, DateFormat.MEDIUM, Locale.US);
String tests = "7:25:43 AM";
String s = fmt.format(d);
if (!s.equals(tests)) {
errln("Fail: " + s + " != " + tests);
} else {
logln("OK: " + s + " == " + tests);
}
}
use of android.icu.text.DateFormat in project j2objc by google.
the class DateFormatRegressionTest method Test4060212.
/**
* @bug 4060212
*/
@Test
public void Test4060212() {
String dateString = "1995-040.05:01:29";
logln("dateString= " + dateString);
logln("Using yyyy-DDD.hh:mm:ss");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-DDD.hh:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date myDate = formatter.parse(dateString, pos);
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG);
String myString = fmt.format(myDate);
logln(myString);
Calendar cal = new GregorianCalendar();
cal.setTime(myDate);
if ((cal.get(Calendar.DAY_OF_YEAR) != 40))
errln("Fail: Got " + cal.get(Calendar.DAY_OF_YEAR) + " Want 40");
logln("Using yyyy-ddd.hh:mm:ss");
formatter = new SimpleDateFormat("yyyy-ddd.hh:mm:ss");
pos.setIndex(0);
myDate = formatter.parse(dateString, pos);
myString = fmt.format(myDate);
logln(myString);
cal.setTime(myDate);
if ((cal.get(Calendar.DAY_OF_YEAR) != 40))
errln("Fail: Got " + cal.get(Calendar.DAY_OF_YEAR) + " Want 40");
}
Aggregations