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


C# Calendar.GetMonthsInYear方法代码示例

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


在下文中一共展示了Calendar.GetMonthsInYear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Age

        /// <summary>
        /// Initializes a new instance of <see cref="Age"/>.
        /// </summary>
        /// <param name="start">The date and time when the age started.</param>
        /// <param name="end">The date and time when the age ended.</param>
        /// <param name="calendar">Calendar used to calculate age.</param>
        public Age(DateTime start, DateTime end, Calendar calendar)
        {
            if (start > end) throw new ArgumentException("The starting date cannot be later than the end date.");

            var startDate = start.Date;
            var endDate = end.Date;

            _years = _months = _days = 0;
            _days += calendar.GetDayOfMonth(endDate) - calendar.GetDayOfMonth(startDate);
            if (_days < 0)
            {
                _days += calendar.GetDaysInMonth(calendar.GetYear(startDate), calendar.GetMonth(startDate));
                _months--;
            }
            _months += calendar.GetMonth(endDate) - calendar.GetMonth(startDate);
            if (_months < 0)
            {
                _months += calendar.GetMonthsInYear(calendar.GetYear(startDate));
                _years--;
            }
            _years += calendar.GetYear(endDate) - calendar.GetYear(startDate);

            var ts = endDate.Subtract(startDate);
            _totalDays = (Int32)ts.TotalDays;
        }
开发者ID:weedazarhub,项目名称:gryffe,代码行数:31,代码来源:Age.cs

示例3: IsValidMonth

        private static bool IsValidMonth( Calendar calendar, int year, int month, int era )
        {
            Contract.Requires( calendar != null );

            if ( month < 1 )
                return false;

            if ( year == calendar.MinSupportedDateTime.Year && month < calendar.MinSupportedDateTime.Month )
                return false;

            return month <= calendar.GetMonthsInYear( year, era );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:12,代码来源:FourFourFiveCalendar.cs

示例4: IsValidMonth

      /// <summary>
      /// Determines if the specified <paramref name="month"/> is a valid month value.
      /// </summary>
      /// <param name="month">The month value.</param>
      /// <param name="year">The year value.</param>
      /// <param name="cal">The calendar to use.</param>
      /// <returns>true if it's a valid month value; false otherwise.</returns>
      private static bool IsValidMonth(int month, int year, Calendar cal)
      {
         year = cal.ToFourDigitYear(year);

         return month >= 1 && month <= cal.GetMonthsInYear(year);
      }
开发者ID:sulerzh,项目名称:DbExporter,代码行数:13,代码来源:DatePickerDateTextBox.cs

示例5: TestDaysInYear

	public void TestDaysInYear (Calendar calendar, int year)
	{
		var daysInYear = calendar.GetDaysInYear (year);
		var daysInMonths = 0;
		var monthInYear = calendar.GetMonthsInYear (year);
		for (var m = 1; m <= monthInYear; m++)
			daysInMonths += calendar.GetDaysInMonth (year, m);

		Assert.AreEqual (daysInYear, daysInMonths, string.Format("Calendar:{0} Year:{1}",calendar.GetType(), year));
	}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:CalendarTest.cs

示例6: Month

        public static int Month( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( Contract.Result<int>() > 0 );
            Contract.Ensures( Contract.Result<int>() <= calendar.GetMonthsInYear( date.Year ) );

            return calendar.GetMonth( date );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:DateTimeExtensions.cs


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