use of android.icu.util.GregorianCalendar in project j2objc by google.
the class DateFormatRegressionTest method Test5006GetShortMonths.
// Note: The purpose of this test case is a little bit questionable. This test
// case expects Islamic month name is different from Gregorian month name.
// However, some locales (in this code, zh_CN) may intentionally use the same
// month name for both Gregorian and Islamic calendars. See #9645.
@Test
public void Test5006GetShortMonths() throws Exception {
// Currently supported NLV locales
// We don't support 'en' alone
Locale ENGLISH = new Locale("en", "US");
Locale ARABIC = new Locale("ar", "");
Locale CZECH = new Locale("cs", "");
Locale GERMAN = new Locale("de", "");
Locale GREEK = new Locale("el", "");
Locale SPANISH = new Locale("es", "");
Locale FRENCH = new Locale("fr", "");
Locale HUNGARIAN = new Locale("hu", "");
Locale ITALIAN = new Locale("it", "");
Locale HEBREW = new Locale("iw", "");
Locale JAPANESE = new Locale("ja", "");
Locale KOREAN = new Locale("ko", "");
Locale POLISH = new Locale("pl", "");
Locale PORTUGUESE = new Locale("pt", "BR");
Locale RUSSIAN = new Locale("ru", "");
Locale TURKISH = new Locale("tr", "");
Locale CHINESE_SIMPLIFIED = new Locale("zh", "CN");
Locale CHINESE_TRADITIONAL = new Locale("zh", "TW");
Locale[] locales = new Locale[] { ENGLISH, ARABIC, CZECH, GERMAN, GREEK, SPANISH, FRENCH, HUNGARIAN, ITALIAN, HEBREW, JAPANESE, KOREAN, POLISH, PORTUGUESE, RUSSIAN, TURKISH, CHINESE_SIMPLIFIED, CHINESE_TRADITIONAL };
String[] islamicCivilTwelfthMonthLocalized = new String[locales.length];
String[] islamicTwelfthMonthLocalized = new String[locales.length];
String[] gregorianTwelfthMonthLocalized = new String[locales.length];
for (int i = 0; i < locales.length; i++) {
Locale locale = locales[i];
// Islamic
android.icu.util.Calendar islamicCivilCalendar = new android.icu.util.IslamicCalendar(locale);
android.icu.text.SimpleDateFormat islamicCivilDateFormat = (android.icu.text.SimpleDateFormat) islamicCivilCalendar.getDateTimeFormat(android.icu.text.DateFormat.FULL, -1, locale);
android.icu.text.DateFormatSymbols islamicCivilDateFormatSymbols = islamicCivilDateFormat.getDateFormatSymbols();
String[] shortMonthsCivil = islamicCivilDateFormatSymbols.getShortMonths();
String twelfthMonthLocalizedCivil = shortMonthsCivil[11];
islamicCivilTwelfthMonthLocalized[i] = twelfthMonthLocalizedCivil;
android.icu.util.IslamicCalendar islamicCalendar = new android.icu.util.IslamicCalendar(locale);
islamicCalendar.setCivil(false);
android.icu.text.SimpleDateFormat islamicDateFormat = (android.icu.text.SimpleDateFormat) islamicCalendar.getDateTimeFormat(android.icu.text.DateFormat.FULL, -1, locale);
android.icu.text.DateFormatSymbols islamicDateFormatSymbols = islamicDateFormat.getDateFormatSymbols();
String[] shortMonths = islamicDateFormatSymbols.getShortMonths();
String twelfthMonthLocalized = shortMonths[11];
islamicTwelfthMonthLocalized[i] = twelfthMonthLocalized;
// Gregorian
android.icu.util.Calendar gregorianCalendar = new android.icu.util.GregorianCalendar(locale);
android.icu.text.SimpleDateFormat gregorianDateFormat = (android.icu.text.SimpleDateFormat) gregorianCalendar.getDateTimeFormat(android.icu.text.DateFormat.FULL, -1, locale);
android.icu.text.DateFormatSymbols gregorianDateFormatSymbols = gregorianDateFormat.getDateFormatSymbols();
shortMonths = gregorianDateFormatSymbols.getShortMonths();
twelfthMonthLocalized = shortMonths[11];
gregorianTwelfthMonthLocalized[i] = twelfthMonthLocalized;
}
// Compare
for (int i = 0; i < locales.length; i++) {
String gregorianTwelfthMonth = gregorianTwelfthMonthLocalized[i];
String islamicCivilTwelfthMonth = islamicCivilTwelfthMonthLocalized[i];
String islamicTwelfthMonth = islamicTwelfthMonthLocalized[i];
logln(locales[i] + ": g:" + gregorianTwelfthMonth + ", ic:" + islamicCivilTwelfthMonth + ", i:" + islamicTwelfthMonth);
if (gregorianTwelfthMonth.equalsIgnoreCase(islamicTwelfthMonth)) {
// Simplified Chinese uses numeric month for both Gregorian/Islamic calendars
if (locales[i] != CHINESE_SIMPLIFIED) {
errln(locales[i] + ": gregorian and islamic are same: " + gregorianTwelfthMonth + ", " + islamicTwelfthMonth);
}
}
if (gregorianTwelfthMonth.equalsIgnoreCase(islamicCivilTwelfthMonth)) {
// Simplified Chinese uses numeric month for both Gregorian/Islamic calendars
if (locales[i] != CHINESE_SIMPLIFIED) {
errln(locales[i] + ": gregorian and islamic-civil are same: " + gregorianTwelfthMonth + ", " + islamicCivilTwelfthMonth);
}
}
if (!islamicTwelfthMonth.equalsIgnoreCase(islamicCivilTwelfthMonth)) {
errln(locales[i] + ": islamic-civil and islamic are NOT same: " + islamicCivilTwelfthMonth + ", " + islamicTwelfthMonth);
}
}
}
use of android.icu.util.GregorianCalendar 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.util.GregorianCalendar in project j2objc by google.
the class DateFormatRegressionTest method TestT11363.
// Test case for numeric field format threading problem
@Test
public void TestT11363() {
class TestThread extends Thread {
SimpleDateFormat fmt;
Date d;
TestThread(SimpleDateFormat fmt, Date d) {
this.fmt = fmt;
this.d = d;
}
public void run() {
String s0 = fmt.format(d);
for (int i = 0; i < 1000; i++) {
String s = fmt.format(d);
if (!s0.equals(s)) {
errln("Result: " + s + ", Expected: " + s0);
}
}
}
}
SimpleDateFormat fmt0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Thread[] threads = new Thread[10];
GregorianCalendar cal = new GregorianCalendar(2014, Calendar.NOVEMBER, 5, 12, 34, 56);
cal.set(Calendar.MILLISECOND, 777);
// calls format() once on the base object to trigger
// lazy initialization stuffs.
fmt0.format(cal.getTime());
for (int i = 0; i < threads.length; i++) {
// Add 1 to all fields to use different numbers in each thread
cal.add(Calendar.YEAR, 1);
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.HOUR_OF_DAY, 1);
cal.add(Calendar.MINUTE, 1);
cal.add(Calendar.SECOND, 1);
cal.add(Calendar.MILLISECOND, 1);
Date d = cal.getTime();
SimpleDateFormat fmt = (SimpleDateFormat) fmt0.clone();
threads[i] = new TestThread(fmt, d);
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
errln(e.toString());
}
}
}
use of android.icu.util.GregorianCalendar 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");
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class TimeZoneRegressionTest method Test4109314.
@Test
public void Test4109314() {
GregorianCalendar testCal = (GregorianCalendar) Calendar.getInstance();
TimeZone PST = TimeZone.getTimeZone("PST");
java.util.Calendar tempcal = java.util.Calendar.getInstance();
tempcal.clear();
tempcal.set(1998, Calendar.APRIL, 4, 22, 0);
Date d1 = tempcal.getTime();
tempcal.set(1998, Calendar.APRIL, 5, 6, 0);
Date d2 = tempcal.getTime();
tempcal.set(1998, Calendar.OCTOBER, 24, 22, 0);
Date d3 = tempcal.getTime();
tempcal.set(1998, Calendar.OCTOBER, 25, 6, 0);
Date d4 = tempcal.getTime();
Object[] testData = { PST, d1, d2, PST, d3, d4 };
boolean pass = true;
for (int i = 0; i < testData.length; i += 3) {
testCal.setTimeZone((TimeZone) testData[i]);
long t = ((Date) testData[i + 1]).getTime();
Date end = (Date) testData[i + 2];
while (t < end.getTime()) {
testCal.setTime(new Date(t));
if (!checkCalendar314(testCal, (TimeZone) testData[i]))
pass = false;
t += 60 * 60 * 1000L;
}
}
if (!pass)
errln("Fail: TZ API inconsistent");
}
Aggregations