use of android.icu.util.Calendar in project j2objc by google.
the class IBMCalendarTest method TestTypes.
@Test
public void TestTypes() {
String[] locs = { "en_US_VALLEYGIRL", "en_US_VALLEYGIRL@collation=phonebook;calendar=japanese", "en_US_VALLEYGIRL@collation=phonebook;calendar=gregorian", "ja_JP@calendar=japanese", "th_TH@calendar=buddhist", "th-TH-u-ca-gregory", "ja_JP_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH_TRADITIONAL@calendar=gregorian", "en_US", // Default calendar for th_TH is buddhist
"th_TH", // th's default region is TH and buddhist is used as default for TH
"th", // Default calendar for any locales with region TH is buddhist
"en_TH", // iso8601 calendar type
"th_TH@calendar=iso8601", "fr_CH", "fr_SA", "fr_CH@rg=sazzzz", "fr_CH@calendar=japanese;rg=sazzzz", // ignore malformed rg tag, use buddhist
"fr_TH@rg=SA", // ignore malformed rg tag, use buddhist
"th@rg=SA" };
// Android patch: Force default Gregorian calendar.
String[] types = { "gregorian", "japanese", "gregorian", "japanese", "buddhist", "gregorian", "japanese", "buddhist", "gregorian", "gregorian", "gregorian", "gregorian", "gregorian", // iso8601 is a gregorian sub type
"gregorian", "gregorian", "gregorian", "gregorian", "japanese", "gregorian", "gregorian" };
for (int i = 0; i < locs.length; i++) {
Calendar cal = Calendar.getInstance(new ULocale(locs[i]));
if (!cal.getType().equals(types[i])) {
errln(locs[i] + " Calendar type " + cal.getType() + " instead of " + types[i]);
}
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class IBMCalendarTest method TestMalaysianInstance.
/**
* Test ms_MY "Malay (Malaysia)" locale. Bug 1543.
*/
@Test
public void TestMalaysianInstance() {
// Malay (Malaysia)
Locale loc = new Locale("ms", "MY");
Calendar cal = Calendar.getInstance(loc);
if (cal == null) {
errln("could not create Malaysian instance");
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class IBMCalendarTest method TestISO8601.
@Test
public void TestISO8601() {
final ULocale[] TEST_LOCALES = { new ULocale("en_US@calendar=iso8601"), new ULocale("en_US@calendar=Iso8601"), new ULocale("th_TH@calendar=iso8601"), new ULocale("ar_EG@calendar=iso8601") };
final int[][] TEST_DATA = { // {<year>, <week# of Jan 1>, <week# year of Jan 1>}
{ 2008, 1, 2008 }, { 2009, 1, 2009 }, { 2010, 53, 2009 }, { 2011, 52, 2010 }, { 2012, 52, 2011 }, { 2013, 1, 2013 }, { 2014, 1, 2014 } };
for (ULocale locale : TEST_LOCALES) {
Calendar cal = Calendar.getInstance(locale);
// calendar type must be Gregorian
if (!cal.getType().equals("gregorian")) {
errln("Error: Gregorian calendar is not used for locale: " + locale);
}
for (int[] data : TEST_DATA) {
cal.set(data[0], Calendar.JANUARY, 1);
int weekNum = cal.get(Calendar.WEEK_OF_YEAR);
int weekYear = cal.get(Calendar.YEAR_WOY);
if (weekNum != data[1] || weekYear != data[2]) {
errln("Error: Incorrect week of year on January 1st, " + data[0] + " for locale " + locale + ": Returned [weekNum=" + weekNum + ", weekYear=" + weekYear + "], Expected [weekNum=" + data[1] + ", weekYear=" + data[2] + "]");
}
}
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class IBMCalendarTest method TestJB4541.
// Tests for jb 4541
@Test
public void TestJB4541() {
ULocale loc = new ULocale("en_US");
// !!! Shouldn't we have an api like this?
// !!! Question: should this reflect those actually available in this copy of ICU, or
// the list of types we assume is available?
// String[] calTypes = Calendar.getAvailableTypes();
final String[] calTypes = { "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew", "islamic", "islamic-civil", "japanese", "roc" };
// constructing a DateFormat with a locale indicating a calendar type should construct a
// date format appropriate to that calendar
final Date time = new Date();
for (int i = 0; i < calTypes.length; ++i) {
ULocale aLoc = loc.setKeywordValue("calendar", calTypes[i]);
logln("locale: " + aLoc);
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, aLoc);
logln("df type: " + df.getClass().getName() + " loc: " + df.getLocale(ULocale.VALID_LOCALE));
Calendar cal = df.getCalendar();
assertEquals("calendar types", cal.getType(), calTypes[i]);
DateFormat df2 = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, ULocale.US);
logln("df2 type: " + df2.getClass().getName() + " loc: " + df2.getLocale(ULocale.VALID_LOCALE));
assertEquals("format results", df.format(time), df2.format(time));
}
// dateFormat.setCalendar should throw exception if wrong format for calendar
if (false) {
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new ULocale("en_US@calendar=chinese"));
logln("dateformat type: " + df.getClass().getName());
Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=chinese"));
logln("calendar type: " + cal.getClass().getName());
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class IslamicTest method TestLimits.
/**
* Test limits of the Islamic calendar
*/
@Test
public void TestLimits() {
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.JANUARY, 1);
IslamicCalendar islamic = newCivil();
doLimitsTest(islamic, null, cal.getTime());
doTheoreticalLimitsTest(islamic, true);
// number of days to test - Islamic calendar starts to exhibit
// rounding errors after year AH3954 - about 2500 years out.
IslamicCalendar islamic2 = new IslamicCalendar();
islamic2.setCalculationType(CalculationType.ISLAMIC);
int testTime = TestFmwk.getExhaustiveness() <= 5 ? 20000 : 800000;
doLimitsTest(islamic2, null, cal.getTime(), testTime);
doTheoreticalLimitsTest(islamic2, true);
}
Aggregations