/// <summary>
        /// Checks that each day from the given start year to the end year (inclusive) is equal
        /// between the BCL and the Noda Time calendar. Additionally, the number of days in each month and year
        /// and the number of months (and leap year status) in each year is checked.
        /// </summary>
        internal static void AssertEquivalent(Calendar bcl, CalendarSystem noda, int fromYear, int toYear)
        {
            // We avoid asking the BCL to create a DateTime on each iteration, simply
            // because the BCL implementation is so slow. Instead, we just check at the start of each month that
            // we're at the date we expect.
            DateTime bclDate = bcl.ToDateTime(fromYear, 1, 1, 0, 0, 0, 0);
            for (int year = fromYear; year <= toYear; year++)
            {
                Assert.AreEqual(bcl.GetDaysInYear(year), noda.GetDaysInYear(year), "Year: {0}", year);
                Assert.AreEqual(bcl.GetMonthsInYear(year), noda.GetMonthsInYear(year), "Year: {0}", year);
                for (int month = 1; month <= noda.GetMonthsInYear(year); month++)
                {
                    // Sanity check at the start of each month. Even this is surprisingly slow.
                    // (These three tests make up about 20% of the total execution time for the test.)
                    Assert.AreEqual(year, bcl.GetYear(bclDate));
                    Assert.AreEqual(month, bcl.GetMonth(bclDate));
                    Assert.AreEqual(1, bcl.GetDayOfMonth(bclDate));

                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                        "Year: {0}; Month: {1}", year, month);
                    Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year), "Year: {0}", year);
                    for (int day = 1; day <= noda.GetDaysInMonth(year, month); day++)
                    {
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.ToDateTimeUnspecified(),
                            "Original calendar system date: {0:yyyy-MM-dd}", nodaDate);
                        Assert.AreEqual(nodaDate, LocalDate.FromDateTime(bclDate, noda));
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                        bclDate = bclDate.AddDays(1);
                    }
                }
            }
        }
        public void SampleDate()
        {
            CalendarSystem copticCalendar = CalendarSystem.GetCopticCalendar(4);
            LocalDateTime  iso            = new LocalDateTime(2004, 6, 9, 0, 0, 0, 0);
            LocalDateTime  coptic         = new LocalDateTime(iso.LocalInstant, copticCalendar);

            Assert.AreEqual(Era.AnnoMartyrum, coptic.Era);
#pragma warning disable 0618
            // The misspelled version of the Era works too.
            Assert.AreEqual(Era.AnnoMartyrm, coptic.Era);
#pragma warning restore 0618
            Assert.AreEqual(18, coptic.CenturyOfEra);
            Assert.AreEqual(20, coptic.YearOfCentury);
            Assert.AreEqual(1720, coptic.YearOfEra);

            Assert.AreEqual(1720, coptic.Year);
            Assert.IsFalse(copticCalendar.IsLeapYear(1720));

            Assert.AreEqual(10, coptic.Month);
            Assert.AreEqual(2, coptic.Day);

            // TODO: Determine whether we should consider the Coptic calendar to use ISO days of the week.
            Assert.AreEqual(IsoDayOfWeek.Wednesday, coptic.IsoDayOfWeek);

            Assert.AreEqual(9 * 30 + 2, coptic.DayOfYear);

            Assert.AreEqual(0, coptic.Hour);
            Assert.AreEqual(0, coptic.Minute);
            Assert.AreEqual(0, coptic.Second);
            Assert.AreEqual(0, coptic.Millisecond);
        }
示例#3
0
 public void LeapYears()
 {
     Assert.IsTrue(Julian.IsLeapYear(1900)); // No 100 year rule...
     Assert.IsFalse(Julian.IsLeapYear(1901));
     Assert.IsTrue(Julian.IsLeapYear(1904));
     Assert.IsTrue(Julian.IsLeapYear(2000));
     Assert.IsTrue(Julian.IsLeapYear(2100)); // No 100 year rule...
     Assert.IsTrue(Julian.IsLeapYear(2400));
     // Check 1BC, 5BC etc...
     Assert.IsTrue(Julian.IsLeapYear(0));
     Assert.IsTrue(Julian.IsLeapYear(-4));
 }
        public void SampleDate()
        {
            CalendarSystem badiCalendar = CalendarSystem.Badi;
            LocalDate      iso          = new LocalDate(2017, 3, 4);
            LocalDate      badi         = iso.WithCalendar(badiCalendar);

            Assert.AreEqual(19, BadiMonth(badi));

            Assert.AreEqual(Era.Bahai, badi.Era);
            Assert.AreEqual(173, badi.YearOfEra);

            Assert.AreEqual(173, badi.Year);
            Assert.IsFalse(badiCalendar.IsLeapYear(173));

            Assert.AreEqual(4, BadiDay(badi));

            Assert.AreEqual(IsoDayOfWeek.Saturday, badi.DayOfWeek);
        }
示例#5
0
        public void SampleDate()
        {
            CalendarSystem wondrousCalendar = CalendarSystem.Wondrous;
            LocalDate      iso      = new LocalDate(2017, 3, 4);
            LocalDate      wondrous = iso.WithCalendar(wondrousCalendar);

            Assert.AreEqual(19, WondrousMonth(wondrous));

            Assert.AreEqual(Era.Bahai, wondrous.Era);
            Assert.AreEqual(173, wondrous.YearOfEra);

            Assert.AreEqual(173, wondrous.Year);
            Assert.IsFalse(wondrousCalendar.IsLeapYear(173));

            Assert.AreEqual(4, WondrousDay(wondrous));

            Assert.AreEqual(IsoDayOfWeek.Saturday, wondrous.DayOfWeek);
        }
示例#6
0
        /// <summary>
        /// Checks that each day from the given start year to the end year (inclusive) is equal
        /// between the BCL and the Noda Time calendar. Additionally, the number of days in each month and year
        /// and the number of months (and leap year status) in each year is checked.
        /// </summary>
        internal static void AssertEquivalent(Calendar bcl, CalendarSystem noda, int fromYear, int toYear)
        {
            // We avoid asking the BCL to create a DateTime on each iteration, simply
            // because the BCL implementation is so slow. Instead, we just check at the start of each month that
            // we're at the date we expect.
            DateTime bclDate = bcl.ToDateTime(fromYear, 1, 1, 0, 0, 0, 0);

            for (int year = fromYear; year <= toYear; year++)
            {
                Assert.AreEqual(bcl.GetDaysInYear(year), noda.GetDaysInYear(year), "Year: {0}", year);
                Assert.AreEqual(bcl.GetMonthsInYear(year), noda.GetMonthsInYear(year), "Year: {0}", year);
                for (int month = 1; month <= noda.GetMonthsInYear(year); month++)
                {
                    // Sanity check at the start of each month. Even this is surprisingly slow.
                    // (These three tests make up about 20% of the total execution time for the test.)
                    Assert.AreEqual(year, bcl.GetYear(bclDate));
                    Assert.AreEqual(month, bcl.GetMonth(bclDate));
                    Assert.AreEqual(1, bcl.GetDayOfMonth(bclDate));

                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                                    "Year: {0}; Month: {1}", year, month);
                    Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year), "Year: {0}", year);
                    for (int day = 1; day <= noda.GetDaysInMonth(year, month); day++)
                    {
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.ToDateTimeUnspecified(),
                                        "Original calendar system date: {0:yyyy-MM-dd}", nodaDate);
                        Assert.AreEqual(nodaDate, LocalDate.FromDateTime(bclDate, noda));
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                        bclDate = bclDate.AddDays(1);
                    }
                }
            }
        }
        public void SampleDate()
        {
            CalendarSystem copticCalendar = CalendarSystem.Coptic;
            LocalDateTime  iso            = new LocalDateTime(2004, 6, 9, 0, 0, 0, 0);
            LocalDateTime  coptic         = iso.WithCalendar(copticCalendar);

            Assert.AreEqual(Era.AnnoMartyrum, coptic.Era);
            Assert.AreEqual(1720, coptic.YearOfEra);

            Assert.AreEqual(1720, coptic.Year);
            Assert.IsFalse(copticCalendar.IsLeapYear(1720));

            Assert.AreEqual(10, coptic.Month);
            Assert.AreEqual(2, coptic.Day);

            Assert.AreEqual(IsoDayOfWeek.Wednesday, coptic.IsoDayOfWeek);

            Assert.AreEqual(9 * 30 + 2, coptic.DayOfYear);

            Assert.AreEqual(0, coptic.Hour);
            Assert.AreEqual(0, coptic.Minute);
            Assert.AreEqual(0, coptic.Second);
            Assert.AreEqual(0, coptic.Millisecond);
        }
        public void HabashAlHasibBasedLeapYear()
        {
            CalendarSystem calendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.HabashAlHasib, IslamicEpoch.Civil);

            Assert.AreEqual(false, calendar.IsLeapYear(1));
            Assert.AreEqual(true, calendar.IsLeapYear(2));
            Assert.AreEqual(false, calendar.IsLeapYear(3));
            Assert.AreEqual(false, calendar.IsLeapYear(4));
            Assert.AreEqual(true, calendar.IsLeapYear(5));
            Assert.AreEqual(false, calendar.IsLeapYear(6));
            Assert.AreEqual(false, calendar.IsLeapYear(7));
            Assert.AreEqual(true, calendar.IsLeapYear(8));
            Assert.AreEqual(false, calendar.IsLeapYear(9));
            Assert.AreEqual(false, calendar.IsLeapYear(10));
            Assert.AreEqual(true, calendar.IsLeapYear(11));
            Assert.AreEqual(false, calendar.IsLeapYear(12));
            Assert.AreEqual(true, calendar.IsLeapYear(13));
            Assert.AreEqual(false, calendar.IsLeapYear(14));
            Assert.AreEqual(false, calendar.IsLeapYear(15));
            Assert.AreEqual(true, calendar.IsLeapYear(16));
            Assert.AreEqual(false, calendar.IsLeapYear(17));
            Assert.AreEqual(false, calendar.IsLeapYear(18));
            Assert.AreEqual(true, calendar.IsLeapYear(19));
            Assert.AreEqual(false, calendar.IsLeapYear(20));
            Assert.AreEqual(true, calendar.IsLeapYear(21));
            Assert.AreEqual(false, calendar.IsLeapYear(22));
            Assert.AreEqual(false, calendar.IsLeapYear(23));
            Assert.AreEqual(true, calendar.IsLeapYear(24));
            Assert.AreEqual(false, calendar.IsLeapYear(25));
            Assert.AreEqual(false, calendar.IsLeapYear(26));
            Assert.AreEqual(true, calendar.IsLeapYear(27));
            Assert.AreEqual(false, calendar.IsLeapYear(28));
            Assert.AreEqual(false, calendar.IsLeapYear(29));
            Assert.AreEqual(true, calendar.IsLeapYear(30));
        }