示例#1
0
        private static IslamicCalendar NewCivil()
        {
            IslamicCalendar civilCalendar = new IslamicCalendar();

            civilCalendar.SetCivil(true);
            return(civilCalendar);
        }
示例#2
0
        public void TestFromJulianDayNumber()
        {
            JulianDay       JD = new JulianDay(1991, 8, 13);
            IslamicCalendar MC = IslamicCalendar.FromJulianDay(JD);

            Assert.AreEqual(MC.Year, 1412);
            Assert.AreEqual(MC.Month, 2);
            Assert.AreEqual(MC.Day, 2);
        }
示例#3
0
        public void TestToJulianDayNumber()
        {
            IslamicCalendar MC = new IslamicCalendar(1421, 1, 1);
            JulianDay       JD = MC.ToJulianDay();

            Assert.AreEqual(JD.Year, 2000);
            Assert.AreEqual(JD.Month, 4);
            Assert.AreEqual(JD.Day, 6);
        }
示例#4
0
        public void TestLimits()
        {
            IBM.ICU.Util.Calendar cal = IBM.ICU.Util.Calendar.GetInstance();
            cal.Set(2007, IBM.ICU.Util.Calendar.JANUARY, 1);
            IslamicCalendar islamic = NewCivil();

            DoLimitsTest(islamic, null, cal.GetTime());
            DoTheoreticalLimitsTest(islamic, true);
        }
示例#5
0
        /// <summary>
        /// A huge list of test cases to make sure that computeTime and computeFields
        /// work properly for a wide range of data in the civil calendar.
        /// </summary>
        ///
        public void TestCivilCases()
        {
            TestCase[] tests =
            {
                //
                // Most of these test cases were taken from the back of
                // "Calendrical Calculations", with some extras added to help
                // debug a few of the problems that cropped up in development.
                //
                // The months in this table are 1-based rather than 0-based,
                // because it's easier to edit that way.
                // Islamic
                // Julian Day Era Year Month Day WkDay Hour Min Sec
                new TestCase(1507231.5d, 0, -1245, 12,  9, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(1660037.5d, 0,  -813,  2, 23, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(1746893.5d, 0,  -568,  4,  1, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(1770641.5d, 0,  -501,  4,  6, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(1892731.5d, 0,  -157, 10, 17, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(1931579.5d, 0,   -47,  6,  3, IBM.ICU.Charset.CalendarTest.MON, 0, 0, 0),
                new TestCase(1974851.5d, 0,    75,  7, 13, IBM.ICU.Charset.CalendarTest.SAT, 0, 0, 0),
                new TestCase(2091164.5d, 0,   403, 10,  5, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2121509.5d, 0,   489,  5, 22, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2155779.5d, 0,   586,  2,  7, IBM.ICU.Charset.CalendarTest.FRI, 0, 0, 0),
                new TestCase(2174029.5d, 0,   637,  8,  7, IBM.ICU.Charset.CalendarTest.SAT, 0, 0, 0),
                new TestCase(2191584.5d, 0,   687,  2, 20, IBM.ICU.Charset.CalendarTest.FRI, 0, 0, 0),
                new TestCase(2195261.5d, 0,   697,  7,  7, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2229274.5d, 0,   793,  7,  1, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2245580.5d, 0,   839,  7,  6, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(2266100.5d, 0,   897,  6,  1, IBM.ICU.Charset.CalendarTest.SAT, 0, 0, 0),
                new TestCase(2288542.5d, 0,   960,  9, 30, IBM.ICU.Charset.CalendarTest.SAT, 0, 0, 0),
                new TestCase(2290901.5d, 0,   967,  5, 27, IBM.ICU.Charset.CalendarTest.SAT, 0, 0, 0),
                new TestCase(2323140.5d, 0,  1058,  5, 18, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(2334848.5d, 0,  1091,  6,  2, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2348020.5d, 0,  1128,  8,  4, IBM.ICU.Charset.CalendarTest.FRI, 0, 0, 0),
                new TestCase(2366978.5d, 0,  1182,  2,  3, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2385648.5d, 0,  1234, 10, 10, IBM.ICU.Charset.CalendarTest.MON, 0, 0, 0),
                new TestCase(2392825.5d, 0,  1255,  1, 11, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(2416223.5d, 0,  1321,  1, 21, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2425848.5d, 0,  1348,  3, 19, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2430266.5d, 0,  1360,  9,  8, IBM.ICU.Charset.CalendarTest.MON, 0, 0, 0),
                new TestCase(2430833.5d, 0,  1362,  4, 13, IBM.ICU.Charset.CalendarTest.MON, 0, 0, 0),
                new TestCase(2431004.5d, 0,  1362, 10,  7, IBM.ICU.Charset.CalendarTest.THU, 0, 0, 0),
                new TestCase(2448698.5d, 0,  1412,  9, 13, IBM.ICU.Charset.CalendarTest.TUE, 0, 0, 0),
                new TestCase(2450138.5d, 0,  1416, 10,  5, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
                new TestCase(2465737.5d, 0,  1460, 10, 12, IBM.ICU.Charset.CalendarTest.WED, 0, 0, 0),
                new TestCase(2486076.5d, 0,  1518,  3,  5, IBM.ICU.Charset.CalendarTest.SUN, 0, 0, 0),
            };

            IslamicCalendar civilCalendar = NewCivil();

            civilCalendar.SetLenient(true);
            DoTestCases(tests, civilCalendar);
        }
示例#6
0
        public void TestBasic()
        {
            IslamicCalendar cal = NewCivil();

            cal.Clear();
            cal.Set(1000, 0, 30);
            Logln("1000/0/30 -> " + cal.Get(IBM.ICU.Charset.CalendarTest.YEAR) + "/" + cal.Get(IBM.ICU.Charset.CalendarTest.MONTH) + "/"
                  + cal.Get(IBM.ICU.Charset.CalendarTest.DATE));
            cal.Clear();
            cal.Set(1, 0, 30);
            Logln("1/0/30 -> " + cal.Get(IBM.ICU.Charset.CalendarTest.YEAR) + "/" + cal.Get(IBM.ICU.Charset.CalendarTest.MONTH) + "/"
                  + cal.Get(IBM.ICU.Charset.CalendarTest.DATE));
        }
示例#7
0
        public void TestRoll()
        {
            int[][] tests = new int[][] {
                new int[] {
                    0x1,
                    QIDAH,
                    2,
                    IBM.ICU.Charset.CalendarTest.MONTH,
                    1, 0x1, HIJJAH, 2
                },
                new int[] {
                    0x1,
                    QIDAH,
                    2,
                    IBM.ICU.Charset.CalendarTest.MONTH,
                    2, 0x1, MUHARRAM, 2
                },
                new int[] {
                    0x1,
                    QIDAH,
                    2,
                    IBM.ICU.Charset.CalendarTest.MONTH,
                    -1, 0x1, SHAWWAL, 2
                },
                new int[] {
                    0x1,
                    MUHARRAM,
                    2,
                    IBM.ICU.Charset.CalendarTest.MONTH,
                    12, 0x1, MUHARRAM, 2
                },
                new int[] {
                    0x1,
                    MUHARRAM,
                    2,
                    IBM.ICU.Charset.CalendarTest.MONTH,
                    13, 0x1, SAFAR, 2
                },
                new int[] {
                    0x1,
                    HIJJAH,
                    1,
                    IBM.ICU.Charset.CalendarTest.DATE,
                    30, 0x1, HIJJAH, 2
                },
                new int[] {
                    0x2,
                    HIJJAH,
                    1,
                    IBM.ICU.Charset.CalendarTest.DATE,
                    31, 0x2, HIJJAH, 2
                },
                new int[] {
                    0x1,
                    MUHARRAM,
                    30,
                    IBM.ICU.Charset.CalendarTest.MONTH,
                    1, 0x1, SAFAR, 29
                },
                new int[] {
                    0x2,
                    HIJJAH,
                    30,
                    IBM.ICU.Charset.CalendarTest.YEAR,
                    -1, 0x1, HIJJAH, 29
                }
            };

            IslamicCalendar cal = NewCivil();

            DoRollAdd(IBM.ICU.Charset.CalendarTest.ROLL, cal, tests);
        }
示例#8
0
        public void TestCoverage()
        {
            {
                // new IslamicCalendar(TimeZone)
                IslamicCalendar cal = new IslamicCalendar(IBM.ICU.Util.TimeZone.GetDefault());
                if (cal == null)
                {
                    Errln("could not create IslamicCalendar with TimeZone");
                }
            }

            {
                // new IslamicCalendar(ULocale)
                IslamicCalendar cal_0 = new IslamicCalendar(IBM.ICU.Util.ULocale.GetDefault());
                if (cal_0 == null)
                {
                    Errln("could not create IslamicCalendar with ULocale");
                }
            }

            {
                // new IslamicCalendar(Locale)
                IslamicCalendar cal_1 = new IslamicCalendar(ILOG.J2CsMapping.Util.Locale.GetDefault());
                if (cal_1 == null)
                {
                    Errln("could not create IslamicCalendar with Locale");
                }
            }

            {
                // new IslamicCalendar(Date)
                IslamicCalendar cal_2 = new IslamicCalendar(DateTime.Now);
                if (cal_2 == null)
                {
                    Errln("could not create IslamicCalendar with Date");
                }
            }

            {
                // new IslamicCalendar(int year, int month, int date)
                IslamicCalendar cal_3 = new IslamicCalendar(800,
                                                            IBM.ICU.Util.IslamicCalendar.RAMADAN, 1);
                if (cal_3 == null)
                {
                    Errln("could not create IslamicCalendar with year,month,date");
                }
            }

            {
                // new IslamicCalendar(int year, int month, int date, int hour, int
                // minute, int second)
                IslamicCalendar cal_4 = new IslamicCalendar(800,
                                                            IBM.ICU.Util.IslamicCalendar.RAMADAN, 1, 1, 1, 1);
                if (cal_4 == null)
                {
                    Errln("could not create IslamicCalendar with year,month,date,hour,minute,second");
                }
            }

            {
                // setCivil/isCivil
                // operations on non-civil calendar
                IslamicCalendar cal_5 = new IslamicCalendar(800,
                                                            IBM.ICU.Util.IslamicCalendar.RAMADAN, 1, 1, 1, 1);
                cal_5.SetCivil(false);
                if (cal_5.IsCivil())
                {
                    Errln("islamic calendar is civil");
                }

                DateTime now = DateTime.Now;
                cal_5.SetTime(now);

                DateTime then = cal_5.GetTime();
                if (!now.Equals(then))
                {
                    Errln("get/set time failed with non-civil islamic calendar");
                }

                Logln(then.ToString());

                cal_5.Add(IBM.ICU.Util.Calendar.MONTH, 1);
                cal_5.Add(IBM.ICU.Util.Calendar.DAY_OF_MONTH, 1);
                cal_5.Add(IBM.ICU.Util.Calendar.YEAR, 1);

                Logln(cal_5.GetTime().ToString());
            }

            {
                // data
                IslamicCalendar cal_6 = new IslamicCalendar(800,
                                                            IBM.ICU.Util.IslamicCalendar.RAMADAN, 1);
                DateTime time = cal_6.GetTime();

                String[] calendarLocales = { "ar_AE", "ar_BH", "ar_DZ", "ar_EG",
                                             "ar_JO", "ar_KW", "ar_OM", "ar_QA","ar_SA",  "ar_SY",
                                             "ar_YE", "ms_MY" };

                String[] formatLocales = { "en", "ar", "fi", "fr", "hu", "iw", "nl" };
                for (int i = 0; i < calendarLocales.Length; ++i)
                {
                    String calLocName = calendarLocales[i];
                    ILOG.J2CsMapping.Util.Locale calLocale = IBM.ICU.Impl.LocaleUtility.GetLocaleFromName(calLocName);
                    cal_6 = new IslamicCalendar(calLocale);

                    for (int j = 0; j < formatLocales.Length; ++j)
                    {
                        String locName = formatLocales[j];
                        ILOG.J2CsMapping.Util.Locale formatLocale = IBM.ICU.Impl.LocaleUtility
                                                                    .GetLocaleFromName(locName);
                        DateFormat format = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal_6,
                                                                                        IBM.ICU.Text.DateFormat.FULL, IBM.ICU.Text.DateFormat.FULL, formatLocale);
                        Logln(calLocName + "/" + locName + " --> "
                              + format.Format(time));
                    }
                }
            }
        }