use of android.icu.util.ChineseCalendar in project j2objc by google.
the class ChineseTest method TestZeroDOM.
/**
* Make sure no Gregorian dates map to Chinese 1-based day of
* month zero. This was a problem with some of the astronomical
* new moon determinations.
*/
@Test
public void TestZeroDOM() {
ChineseCalendar cal = new ChineseCalendar();
GregorianCalendar greg = new GregorianCalendar(1989, Calendar.SEPTEMBER, 1);
logln("Start: " + greg.getTime());
for (int i = 0; i < 1000; ++i) {
cal.setTimeInMillis(greg.getTimeInMillis());
if (cal.get(Calendar.DAY_OF_MONTH) == 0) {
errln("Fail: " + greg.getTime() + " -> " + cal.get(Calendar.EXTENDED_YEAR) + "/" + cal.get(Calendar.MONTH) + (cal.get(Calendar.IS_LEAP_MONTH) == 1 ? "(leap)" : "") + "/" + cal.get(Calendar.DAY_OF_MONTH));
}
greg.add(Calendar.DAY_OF_YEAR, 1);
}
logln("End: " + greg.getTime());
}
use of android.icu.util.ChineseCalendar in project j2objc by google.
the class ChineseTest method TestRoll.
/**
* Test the behavior of ChineseCalendar.roll(). The only real
* nastiness with roll is the MONTH field around leap months.
*/
@Test
public void TestRoll() {
int[][] tests = new int[][] { // normal
{ 4642, 3, 0, 15, MONTH, 3, 4642, 6, 0, 15 }, // normal
{ 4642, 3, 0, 15, MONTH, 11, 4642, 2, 0, 15 }, // across year
{ 4639, 12, 0, 15, MONTH, 1, 4639, 1, 0, 15 }, // across year
{ 4640, 1, 0, 15, MONTH, -1, 4640, 12, 0, 15 }, // 4=leap
{ 4638, 3, 0, 15, MONTH, 3, 4638, 5, 0, 15 }, // 4=leap
{ 4638, 3, 0, 15, MONTH, 16, 4638, 5, 0, 15 }, // 4=leap
{ 4638, 3, 0, 15, MONTH, 2, 4638, 4, 1, 15 }, // 4=leap
{ 4638, 3, 0, 15, MONTH, 28, 4638, 4, 1, 15 }, // 4=leap
{ 4638, 4, 0, 15, MONTH, 1, 4638, 4, 1, 15 }, // 4=leap
{ 4638, 4, 0, 15, MONTH, -12, 4638, 4, 1, 15 }, // 4=leap
{ 4638, 4, 1, 15, MONTH, 1, 4638, 5, 0, 15 }, // 4=leap
{ 4638, 4, 1, 15, MONTH, -25, 4638, 5, 0, 15 }, // dom should pin
{ 4638, 4, 0, 30, MONTH, 1, 4638, 4, 1, 29 }, // dom should pin
{ 4638, 4, 0, 30, MONTH, 14, 4638, 4, 1, 29 }, // no dom pin
{ 4638, 4, 0, 30, MONTH, 15, 4638, 5, 0, 30 }, // dom should pin
{ 4638, 4, 0, 30, MONTH, -10, 4638, 6, 0, 29 } };
ChineseCalendar cal = new ChineseCalendar();
doRollAdd(ROLL, cal, tests);
}
use of android.icu.util.ChineseCalendar in project j2objc by google.
the class ChineseTest method TestFormat.
/**
* Test formatting.
* Q: Why is this in Calendar tests instead of Format tests?
* Note: This test assumes that Chinese calendar formatted dates can be parsed
* unambiguously to recover the original Date that was formatted. This is not
* currently true since Chinese calendar formatted dates do not include an era.
* To address this will require formatting/parsing of fields from some other
* associated calendar, as per ICU ticket #9043. This test should be timebombed
* until that ticket is addressed.
*/
@Test
public void TestFormat() {
ChineseCalendar cal = new ChineseCalendar();
DateFormat fmt = DateFormat.getDateTimeInstance(cal, DateFormat.DEFAULT, DateFormat.DEFAULT);
java.util.Calendar tempcal = java.util.Calendar.getInstance();
tempcal.clear();
Date[] DATA = new Date[2];
tempcal.set(2001, Calendar.MAY, 22);
DATA[0] = tempcal.getTime();
tempcal.set(2001, Calendar.MAY, 23);
DATA[1] = tempcal.getTime();
for (int i = 0; i < DATA.length; ++i) {
String s = fmt.format(DATA[i]);
try {
Date e = fmt.parse(s);
if (e.equals(DATA[i])) {
logln("Ok: " + DATA[i] + " -> " + s + " -> " + e);
} else {
errln("FAIL: " + DATA[i] + " -> " + s + " -> " + e);
}
} catch (java.text.ParseException e) {
errln("Fail: " + s + " -> parse failure at " + e.getErrorOffset());
errln(e.toString());
}
}
}
Aggregations