public void TestInitWithCurrentTime() { // jb4555 // if the chinese calendar current millis isn't called, the default year // is wrong. // this test is assuming the 'year' is the current cycle // so when we cross a cycle boundary, the target will need to change // that shouldn't be for awhile yet... ChineseCalendar cc = new ChineseCalendar(); cc.Set(IBM.ICU.Util.Calendar.YEAR, 22); cc.Set(IBM.ICU.Util.Calendar.MONTH, 0); // need to set leap month flag off, otherwise, the test case always // fails when // current time is in a leap month cc.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, 0); cc.Set(IBM.ICU.Util.Calendar.DATE, 19); cc.Set(IBM.ICU.Util.Calendar.HOUR_OF_DAY, 0); cc.Set(IBM.ICU.Util.Calendar.MINUTE, 0); cc.Set(IBM.ICU.Util.Calendar.SECOND, 0); cc.Set(IBM.ICU.Util.Calendar.MILLISECOND, 0); cc.Add(IBM.ICU.Util.Calendar.DATE, 1); DateTime target = new DateTime(105, IBM.ICU.Util.Calendar.FEBRUARY, 28); DateTime result = cc.GetTime(); AssertEquals("chinese and gregorian date should match", target, result); }
internal void DoRollAdd(bool roll, ChineseCalendar cal, int[][] tests) { String name = (roll) ? "rolling" : "adding"; for (int i = 0; i < tests.Length; i++) { int[] test = tests[i]; cal.Clear(); cal.Set(IBM.ICU.Util.Calendar.EXTENDED_YEAR, test[0]); cal.Set(IBM.ICU.Util.Calendar.MONTH, test[1] - 1); cal.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, test[2]); cal.Set(IBM.ICU.Util.Calendar.DAY_OF_MONTH, test[3]); if (roll) { cal.Roll(test[4], test[5]); } else { cal.Add(test[4], test[5]); } if (cal.Get(IBM.ICU.Util.Calendar.EXTENDED_YEAR) != test[6] || cal.Get(IBM.ICU.Charset.CalendarTest.MONTH) != (test[7] - 1) || cal.Get(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH) != test[8] || cal.Get(IBM.ICU.Charset.CalendarTest.DATE) != test[9]) { Errln("Fail: " + name + " " + YmdToString(test[0], test[1] - 1, test[2], test[3]) + " " + IBM.ICU.Charset.CalendarTest.FieldName(test[4]) + " by " + test[5] + ": expected " + YmdToString(test[6], test[7] - 1, test[8], test[9]) + ", got " + IBM.ICU.Charset.CalendarTest.YmdToString(cal)); } else if (IsVerbose()) { Logln("OK: " + name + " " + YmdToString(test[0], test[1] - 1, test[2], test[3]) + " " + IBM.ICU.Charset.CalendarTest.FieldName(test[4]) + " by " + test[5] + ": got " + IBM.ICU.Charset.CalendarTest.YmdToString(cal)); } } }