當前位置: 首頁>>代碼示例>>C#>>正文


C# Calendar.GetDaysInYear方法代碼示例

本文整理匯總了C#中System.Globalization.Calendar.GetDaysInYear方法的典型用法代碼示例。如果您正苦於以下問題:C# Calendar.GetDaysInYear方法的具體用法?C# Calendar.GetDaysInYear怎麽用?C# Calendar.GetDaysInYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Globalization.Calendar的用法示例。


在下文中一共展示了Calendar.GetDaysInYear方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: Year

 // ----------------------------------------------------------------------
 public static TimeSpan Year( Calendar calendar, int year )
 {
     return Days( calendar.GetDaysInYear( year ) );
 }
開發者ID:HoLoveSalt,項目名稱:showhotel,代碼行數:5,代碼來源:Duration.cs

示例3: 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

示例4: InternalGetWeekOfYearFullDays

        // This is copied from the generic implementation of GetWeekOfYearFullDays() in Calendar.cs.  The generic implementation is not good enough 
        // in the case of FristFullWeek and FirstFourDayWeek since it needs the data for B.C. year 1 near 0001/1/1.
        // We override the generic implementation to handle this special case.

        // Parameters 
        //
        internal static int InternalGetWeekOfYearFullDays(Calendar cal, DateTime time, int firstDayOfWeek, int fullDays, int daysOfMinYearMinusOne) { 
            int dayForJan1; 
            int offset;
            int day; 

            int dayOfYear = cal.GetDayOfYear(time) - 1; // Make the day of year to be 0-based, so that 1/1 is day 0.
            //
            // Calculate the number of days between the first day of year (1/1) and the first day of the week. 
            // This value will be a positive value from 0 ~ 6.  We call this value as "offset".
            // 
            // If offset is 0, it means that the 1/1 is the start of the first week. 
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sun      Mon     Tue     Wed     Thu     Fri     Sat 
            //     12/31    1/1     1/2     1/3     1/4     1/5     1/6
            //              +--> First week starts here.
            //
            // If offset is 1, it means that the first day of the week is 1 day ahead of 1/1. 
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sun      Mon     Tue     Wed     Thu     Fri     Sat 
            //     1/1      1/2     1/3     1/4     1/5     1/6     1/7 
            //              +--> First week starts here.
            // 
            // If offset is 2, it means that the first day of the week is 2 days ahead of 1/1.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sat      Sun     Mon     Tue     Wed     Thu     Fri     Sat
            //     1/1      1/2     1/3     1/4     1/5     1/6     1/7     1/8 
            //                      +--> First week starts here.
 
 

            // Day of week is 0-based. 
            // Get the day of week for 1/1.  This can be derived from the day of week of the target day.
            // Note that we can get a negative value.  It's ok since we are going to make it a positive value when calculating the offset.
            dayForJan1 = (int)cal.GetDayOfWeek(time) - (dayOfYear % 7);
 
            // Now, calucalte the offset.  Substract the first day of week from the dayForJan1.  And make it a positive value.
            offset = (firstDayOfWeek - dayForJan1 + 14) % 7; 
            if (offset != 0 && offset >= fullDays) 
            {
                // 
                // If the offset is greater than the value of fullDays, it means that
                // the first week of the year starts on the week where Jan/1 falls on.
                //
                offset -= 7; 
            }
            // 
            // Calculate the day of year for specified time by taking offset into account. 
            //
            day = dayOfYear - offset; 
            if (day >= 0) {
                //
                // If the day of year value is greater than zero, get the week of year.
                // 
                return (day/7 + 1);
            } 
            // 
            // Otherwise, the specified time falls on the week of previous year.
            // Note that it is not always week 52 or 53, because it depends on the calendar.  Different calendars have different number of days in a year. 
            //

            // Repeat the previous calculation logic using the previous year and calculate the week of year for the last day of previous year.
            int year = cal.GetYear(time); 
            if (year <= cal.GetYear(cal.MinSupportedDateTime)) {
                // This specified time is in 0001/1/1 ~ 0001/1/7. 
                dayOfYear = daysOfMinYearMinusOne; 
            } else {
                dayOfYear = cal.GetDaysInYear(year - 1); 
            }
            dayForJan1 = dayForJan1 - (dayOfYear % 7);
            // Now, calucalte the offset.  Substract the first day of week from the dayForJan1.  And make it a positive value.
            offset = (firstDayOfWeek - dayForJan1 + 14) % 7; 
            if (offset != 0 && offset >= fullDays)
            { 
                // 
                // If the offset is greater than the value of fullDays, it means that
                // the first week of the year starts on the week where Jan/1 falls on. 
                //
                offset -= 7;
            }
            // 
            // Calculate the day of year for specified time by taking offset into account.
            // 
            day = dayOfYear - offset; 
            return (day/7 + 1);
        } 
開發者ID:sjyanxin,項目名稱:WPFSource,代碼行數:91,代碼來源:GregorianCalendar.cs

示例5: InternalGetWeekOfYearFullDays

 internal static int InternalGetWeekOfYearFullDays(Calendar cal, DateTime time, int firstDayOfWeek, int fullDays, int daysOfMinYearMinusOne)
 {
     int daysInYear = cal.GetDayOfYear(time) - 1;
     int num = ((int) cal.GetDayOfWeek(time)) - (daysInYear % 7);
     int num2 = ((firstDayOfWeek - num) + 14) % 7;
     if ((num2 != 0) && (num2 >= fullDays))
     {
         num2 -= 7;
     }
     int num3 = daysInYear - num2;
     if (num3 < 0)
     {
         int year = cal.GetYear(time);
         if (year <= cal.GetYear(cal.MinSupportedDateTime))
         {
             daysInYear = daysOfMinYearMinusOne;
         }
         else
         {
             daysInYear = cal.GetDaysInYear(year - 1);
         }
         num -= daysInYear % 7;
         num2 = ((firstDayOfWeek - num) + 14) % 7;
         if ((num2 != 0) && (num2 >= fullDays))
         {
             num2 -= 7;
         }
         num3 = daysInYear - num2;
     }
     return ((num3 / 7) + 1);
 }
開發者ID:randomize,項目名稱:VimConfig,代碼行數:31,代碼來源:GregorianCalendar.cs


注:本文中的System.Globalization.Calendar.GetDaysInYear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。