Beispiel #1
0
        public void TestLimits()
        {
            // The number of days and the start date can be adjusted
            // arbitrarily to either speed up the test or make it more
            // thorough, but try to test at least a full year, preferably a
            // full non-leap and a full leap year.

            // Final parameter is either number of days, if > 0, or test
            // duration in seconds, if < 0.
            IBM.ICU.Util.Calendar tempcal = IBM.ICU.Util.Calendar.GetInstance();
            tempcal.Clear();
            tempcal.Set(1989, IBM.ICU.Util.Calendar.NOVEMBER, 1);
            ChineseCalendar chinese = new ChineseCalendar();

            if (!SkipIfBeforeICU(3, 9, 0))
            {
                DoLimitsTest(chinese, null, tempcal.GetTime());
            }
            DoTheoreticalLimitsTest(chinese, true);
        }
Beispiel #2
0
        public void TestFormat()
        {
            ChineseCalendar cal = new ChineseCalendar();
            DateFormat      fmt = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal,
                                                                              IBM.ICU.Text.DateFormat.DEFAULT, IBM.ICU.Text.DateFormat.DEFAULT);

            IBM.ICU.Util.Calendar tempcal = IBM.ICU.Util.Calendar.GetInstance();
            tempcal.Clear();

            DateTime[] DATA = new DateTime[2];
            tempcal.Set(2001, IBM.ICU.Util.Calendar.MAY, 22);
            DATA[0] = tempcal.GetTime();
            tempcal.Set(2001, IBM.ICU.Util.Calendar.MAY, 23);
            DATA[1] = tempcal.GetTime();
            // Wed May 23 2001 = Month 4(leap), Day 1, Year 18, Cycle 78

            for (int i = 0; i < DATA.Length; ++i)
            {
                String s = fmt.Format(DATA[i]);
                try
                {
                    DateTime e = fmt.Parse(s);
                    if (e.Equals(DATA[i]))
                    {
                        Logln("Ok: " + DATA[i] + " -> " + s + " -> " + e);
                    }
                    else
                    {
                        Errln("FAIL: " + DATA[i] + " -> " + s + " -> " + e);
                    }
                }
                catch (ILOG.J2CsMapping.Util.ParseException e_0)
                {
                    Errln("Fail: " + s + " -> parse failure at "
                          + e_0.GetErrorOffset());
                    Errln(e_0.ToString());
                }
            }
        }
Beispiel #3
0
        public void TestMapping()
        {
            int[] DATA =
            {
                // (Note: months are 1-based)
                // Gregorian Chinese
                1964,  9,    4, 4601,    7,  0,   28, 1964,  9,    5, 4601,    7, 0,   29, 1964,
                9,     6, 4601,    8,    0,  1, 1964,    9,  7, 4601,    8,    0, 2, 1961,   12, 25,
                4598, 11,    0,   18, 1999,  6,    4, 4636,  4,    0,   21,

                1990,  5,   23, 4627,    4,  0,   29, 1990,  5,   24, 4627,    5, 0,    1, 1990,
                6,    22, 4627,    5,    0, 30, 1990,    6, 23, 4627,    5,    1, 1, 1990,    7, 20,
                4627,  5,    1,   28, 1990,  7,   21, 4627,  5,    1,   29, 1990, 7,   22, 4627,
                6,     0,    1,
            };

            ChineseCalendar cal = new ChineseCalendar();
            StringBuilder   buf = new StringBuilder();

            Logln("Gregorian -> Chinese");
            // java.util.Calendar grego = java.util.Calendar.getInstance();
            IBM.ICU.Util.Calendar grego = IBM.ICU.Util.Calendar.GetInstance();
            grego.Clear();
            for (int i = 0; i < DATA.Length;)
            {
                grego.Set(DATA[i++], DATA[i++] - 1, DATA[i++]);
                DateTime date = grego.GetTime();
                cal.SetTime(date);
                int y  = cal.Get(IBM.ICU.Util.Calendar.EXTENDED_YEAR);
                int m  = cal.Get(IBM.ICU.Util.Calendar.MONTH) + 1; // 0-based -> 1-based
                int L  = cal.Get(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH);
                int d  = cal.Get(IBM.ICU.Util.Calendar.DAY_OF_MONTH);
                int yE = DATA[i++]; // Expected y, m, isLeapMonth, d
                int mE = DATA[i++]; // 1-based
                int LE = DATA[i++];
                int dE = DATA[i++];
                buf.Length = 0;
                buf.Append(date + " -> ");
                buf.Append(y + "/" + m + ((L == 1) ? "(leap)" : "") + "/" + d);
                if (y == yE && m == mE && L == LE && d == dE)
                {
                    Logln("OK: " + buf.ToString());
                }
                else
                {
                    Errln("Fail: " + buf.ToString() + ", expected " + yE + "/" + mE
                          + ((LE == 1) ? "(leap)" : "") + "/" + dE);
                }
            }

            Logln("Chinese -> Gregorian");
            for (int i_0 = 0; i_0 < DATA.Length;)
            {
                grego.Set(DATA[i_0++], DATA[i_0++] - 1, DATA[i_0++]);
                DateTime dexp         = grego.GetTime();
                int      cyear        = DATA[i_0++];
                int      cmonth       = DATA[i_0++];
                int      cisleapmonth = DATA[i_0++];
                int      cdayofmonth  = DATA[i_0++];
                cal.Clear();
                cal.Set(IBM.ICU.Util.Calendar.EXTENDED_YEAR, cyear);
                cal.Set(IBM.ICU.Util.Calendar.MONTH, cmonth - 1);
                cal.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, cisleapmonth);
                cal.Set(IBM.ICU.Util.Calendar.DAY_OF_MONTH, cdayofmonth);
                DateTime date_1 = cal.GetTime();
                buf.Length = 0;
                buf.Append(cyear + "/" + cmonth
                           + ((cisleapmonth == 1) ? "(leap)" : "") + "/" + cdayofmonth);
                buf.Append(" -> " + date_1);
                if (date_1.Equals(dexp))
                {
                    Logln("OK: " + buf.ToString());
                }
                else
                {
                    Errln("Fail: " + buf.ToString() + ", expected " + dexp);
                }
            }
        }