当前位置: 首页>>代码示例>>C#>>正文


C# Calendar.IsLeapYear方法代码示例

本文整理汇总了C#中System.Globalization.Calendar.IsLeapYear方法的典型用法代码示例。如果您正苦于以下问题:C# Calendar.IsLeapYear方法的具体用法?C# Calendar.IsLeapYear怎么用?C# Calendar.IsLeapYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.Calendar的用法示例。


在下文中一共展示了Calendar.IsLeapYear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssertEquivalent

        /// <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);
                    }
                }
            }
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:40,代码来源:BclEquivalenceHelper.cs

示例2: CalendarSystemForCalendar

 /// <summary>
 /// Tries to work out a roughly-matching calendar system for the given BCL calendar.
 /// This is needed where we're testing whether days of the week match - even if we can
 /// get day/month/year values to match without getting the calendar right, the calendar
 /// affects the day of week.
 /// </summary>
 internal static CalendarSystem CalendarSystemForCalendar(Calendar bcl)
 {
     // Yes, this is horrible... but the specific calendars aren't available to test
     // against in the PCL
     switch (bcl.GetType().Name)
     {
         case "GregorianCalendar": return CalendarSystem.Iso;
         case "HijriCalendar": return CalendarSystem.IslamicBcl;
         case "HebrewCalendar": return CalendarSystem.HebrewCivil;
         case "PersianCalendar": return bcl.IsLeapYear(1) ? CalendarSystem.PersianSimple : CalendarSystem.PersianAstronomical;
         case "UmAlQuraCalendar": return CalendarSystem.UmAlQura;
         case "JulianCalendar":
             return CalendarSystem.Julian;
         default:
             // No idea - we can't test with this calendar...
             return null;
     }
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:24,代码来源:BclCalendars.cs


注:本文中的System.Globalization.Calendar.IsLeapYear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。