use of android.icu.util.Calendar in project j2objc by google.
the class CalendarRegressionTest method Test4096231.
@Test
public void Test4096231() {
TimeZone GMT = TimeZone.getTimeZone("GMT");
TimeZone PST = TimeZone.getTimeZone("PST");
int sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997;
Calendar cal1 = new GregorianCalendar(PST);
cal1.setTime(new Date(880698639000L));
int p;
logln("PST 1 is: " + (p = cal1.get(Calendar.HOUR_OF_DAY)));
cal1.setTimeZone(GMT);
// Issue 1: Changing the timezone doesn't change the
// represented time.
int h1, h2;
logln("GMT 1 is: " + (h1 = cal1.get(Calendar.HOUR_OF_DAY)));
cal1.setTime(new Date(880698639000L));
logln("GMT 2 is: " + (h2 = cal1.get(Calendar.HOUR_OF_DAY)));
// to 4177484.
if (p == h1 || h1 != h2)
errln("Fail: Hour same in different zones");
Calendar cal2 = new GregorianCalendar(GMT);
Calendar cal3 = new GregorianCalendar(PST);
cal2.set(Calendar.MILLISECOND, 0);
cal3.set(Calendar.MILLISECOND, 0);
cal2.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH), cal1.get(Calendar.HOUR_OF_DAY), cal1.get(Calendar.MINUTE), cal1.get(Calendar.SECOND));
long t1, t2, t3, t4;
logln("RGMT 1 is: " + (t1 = cal2.getTime().getTime()));
cal3.set(year, month, day, hr, min, sec);
logln("RPST 1 is: " + (t2 = cal3.getTime().getTime()));
cal3.setTimeZone(GMT);
logln("RGMT 2 is: " + (t3 = cal3.getTime().getTime()));
cal3.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH), cal1.get(Calendar.HOUR_OF_DAY), cal1.get(Calendar.MINUTE), cal1.get(Calendar.SECOND));
// Issue 2: Calendar continues to use the timezone in its
// constructor for set() conversions, regardless
// of calls to setTimeZone()
logln("RGMT 3 is: " + (t4 = cal3.getTime().getTime()));
if (t1 == t2 || t1 != t4 || t2 != t3)
errln("Fail: Calendar zone behavior faulty");
}
use of android.icu.util.Calendar in project j2objc by google.
the class CalendarRegressionTest method TestCalendarType6816.
@Test
public void TestCalendarType6816() {
Locale loc = new Locale("en", "TH");
Calendar cal = Calendar.getInstance(loc);
String calType = cal.getType();
// Android patch: Force default Gregorian calendar.
if (!calType.equals("gregorian")) {
errln("FAIL: Calendar type for en_TH should still be gregorian");
}
// Android patch end.
}
use of android.icu.util.Calendar in project j2objc by google.
the class JapaneseTest method TestJapaneseYear3282.
@Test
public void TestJapaneseYear3282() {
Calendar c = Calendar.getInstance(ULocale.ENGLISH);
c.set(2003, Calendar.SEPTEMBER, 25);
JapaneseCalendar jcal = new JapaneseCalendar();
// jcal.setTime(new Date(1187906308151L)); alternate value
jcal.setTime(c.getTime());
logln("Now is: " + jcal.getTime());
c.setTime(jcal.getTime());
int nowYear = c.get(Calendar.YEAR);
logln("Now year: " + nowYear);
SimpleDateFormat jdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(jcal, SimpleDateFormat.DEFAULT, Locale.getDefault());
jdf.applyPattern("G yy/MM/dd");
String text = jdf.format(jcal.getTime());
logln("Now is: " + text + " (in Japan)");
try {
Date date = jdf.parse(text);
logln("But is this not the date?: " + date);
c.setTime(date);
int thenYear = c.get(Calendar.YEAR);
logln("Then year: " + thenYear);
if (thenYear != nowYear) {
errln("Nowyear " + nowYear + " is not thenyear " + thenYear);
} else {
logln("Nowyear " + nowYear + " == thenyear " + thenYear);
}
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class CopticTest method TestYear.
@Test
public void TestYear() {
// Gregorian Calendar
Calendar gCal = new GregorianCalendar();
Date gToday = gCal.getTime();
gCal.add(GregorianCalendar.MONTH, 2);
Date gFuture = gCal.getTime();
DateFormat gDF = DateFormat.getDateInstance(gCal, DateFormat.FULL);
logln("gregorian calendar: " + gDF.format(gToday) + " + 2 months = " + gDF.format(gFuture));
// Coptic Calendar
CopticCalendar cCal = new CopticCalendar();
Date cToday = cCal.getTime();
cCal.add(CopticCalendar.MONTH, 2);
Date cFuture = cCal.getTime();
DateFormat cDF = DateFormat.getDateInstance(cCal, DateFormat.FULL);
logln("coptic calendar: " + cDF.format(cToday) + " + 2 months = " + cDF.format(cFuture));
// EthiopicCalendar
EthiopicCalendar eCal = new EthiopicCalendar();
Date eToday = eCal.getTime();
// add 2 months
eCal.add(EthiopicCalendar.MONTH, 2);
eCal.setAmeteAlemEra(false);
Date eFuture = eCal.getTime();
DateFormat eDF = DateFormat.getDateInstance(eCal, DateFormat.FULL);
logln("ethiopic calendar: " + eDF.format(eToday) + " + 2 months = " + eDF.format(eFuture));
}
use of android.icu.util.Calendar in project j2objc by google.
the class CopticTest method TestLimits.
/**
* Test limits of the Coptic calendar
*/
@Test
public void TestLimits() {
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.JANUARY, 1);
CopticCalendar coptic = new CopticCalendar();
doLimitsTest(coptic, null, cal.getTime());
doTheoreticalLimitsTest(coptic, true);
}
Aggregations