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


C# GregorianCalendar.GetDaysInYear方法代码示例

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


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

示例1: AreAnyRoomsInRangeAvailable

        /// <summary>
        /// Returns false only if all fields for the range has availability set to false
        /// </summary>
        /// <remarks>
        /// This method is useful to checking un-availability, as it will return true if there is any availability in a date range
        /// </remarks>        
        /// <param name="availability">The record to check</param>
        /// <param name="fromDayOfYear">From which Day Of Year</param>
        /// <param name="toDayOfYear">OPTIONAL: to which Day Of Year, last day in sequence will not be checked will not be checked</param>
        /// <returns>True if any of the rooms in the range specified is available otherwise false</returns>
        public static bool AreAnyRoomsInRangeAvailable(RoomsAvailability availability, int fromDayOfYear, int? toDayOfYear = null)
        {
            // if the availability is null means that the room is assumed to be available 
            if(availability == null)
            {
                return true;
            }

            //because we have leap years we need to consider either 365 or 366 days
            if (!toDayOfYear.HasValue)
            {
                GregorianCalendar calendar = new GregorianCalendar();
                toDayOfYear = calendar.GetDaysInYear(availability.Year);
            }

            bool isAvailable = false;
            for (int d = fromDayOfYear; d < toDayOfYear; d++)
            {
                string propertyName = String.Format("IsDay{0:000}Available", d);
                PropertyInfo p = typeof(RoomsAvailability).GetProperty(propertyName);

                isAvailable = isAvailable | (bool)p.GetValue(availability, null);
            }
            return isAvailable;
        }
开发者ID:ognjenm,项目名称:egle,代码行数:35,代码来源:RoomAvailabilityHelper.cs

示例2: GetCalendarDaysFor

        public static List<ActivityDay> GetCalendarDaysFor(int? period/*0=yearly, 1=monthly and 2=weekly*/)
        {
            var days = new List<ActivityDay>();
            //var calendar = new ActivityCalendar();
                var calendarYear = new GregorianCalendar();
                switch (period)
                {
                    case 0:

                        var dayNumber=(int)DateTime.Now.DayOfWeek;
                        var weekDay = DateTime.Now.AddDays(-dayNumber);

                        for (int i=0;i<7;i++)
                        {

                            days.Add(new ActivityDay {
                                Date = weekDay,
                                Name = calendarYear.GetDayOfWeek(weekDay).ToString(),
                                Status=true,
                                ActivityStatus = calendarYear.GetDayOfWeek(weekDay) == DayOfWeek.Friday ?
                                DayStatus.Holiday
                                :DayStatus.Active});
                            weekDay=weekDay.AddDays(1);
                        }
                        break;
                    case 1:

                        var daysInMonth=calendarYear.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                        for (int day = 1; day <= daysInMonth;day++ )
                        {
                            var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, day);
                            days.Add(new ActivityDay
                            {
                                Date = date,
                                Name = calendarYear.GetDayOfWeek(date).ToString(),
                                Status = true,
                                ActivityStatus = calendarYear.GetDayOfWeek(date) ==
                                DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active
                            });
                        }
                        break;
                    default:

                        var daysInYr=calendarYear.GetDaysInYear(DateTime.Now.Year);
                        var startOfYr = new DateTime(DateTime.Now.Year, 1, 1);
                        for (int day = 0; day < daysInYr; day++)
                        {
                            var dateOfYr = new ActivityDay {Date=startOfYr.AddDays(day) };
                            dateOfYr.Name = calendarYear.GetDayOfWeek(dateOfYr.Date).ToString();
                            dateOfYr.Status = true;
                            dateOfYr.ActivityStatus = calendarYear.GetDayOfWeek(dateOfYr.Date) == DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active;
                            days.Add(dateOfYr);

                        }

                        break;
                }
                return days;
        }
开发者ID:naveedjb,项目名称:fahm-e-islam,代码行数:59,代码来源:Utils.cs

示例3: GetDaysInYearShouldReturnCorrectCount

        public void GetDaysInYearShouldReturnCorrectCount()
        {
            var target = new GregorianFiscalCalendar( 7 );
            var calendar = new GregorianCalendar();

            for ( var year = 1998; year <= 2030; year++ )
                Assert.Equal( calendar.GetDaysInYear( year ), target.GetDaysInYear( year ) );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:GregorianFiscalCalendarTest.cs

示例4: PosTest3

 public void PosTest3()
 {
     System.Globalization.Calendar kC = new KoreanCalendar();
     System.Globalization.Calendar gC = new GregorianCalendar();
     DateTime dateTime = new GregorianCalendar().ToDateTime(2004, 2, 29, 0, 0, 0, 0);
     int expectedValue = gC.GetDaysInYear(dateTime.Year, gC.GetEra(dateTime));
     int actualValue;
     actualValue = kC.GetDaysInYear(dateTime.Year + 2333, kC.GetEra(dateTime));
     Assert.Equal(expectedValue, actualValue);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:KoreanCalendarGetDaysInYear.cs

示例5: PosTest5

 public void PosTest5()
 {
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     int year;
     int expectedDays, actualDays;
     year = myCalendar.MinSupportedDateTime.Year;
     expectedDays = (IsLeapYear(year)) ? c_DAYS_IN_LEAP_YEAR : c_DAYS_IN_COMMON_YEAR;
     actualDays = myCalendar.GetDaysInYear(year);
     Assert.Equal(expectedDays, actualDays);
 }
开发者ID:kkurni,项目名称:corefx,代码行数:10,代码来源:GregorianCalendarGetDaysInYear.cs

示例6: PosTest2

 public void PosTest2()
 {
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     int year;
     int expectedDays, actualDays;
     year = GetACommonYear(myCalendar);
     expectedDays = c_DAYS_IN_COMMON_YEAR;
     actualDays = myCalendar.GetDaysInYear(year);
     Assert.Equal(expectedDays, actualDays);
 }
开发者ID:kkurni,项目名称:corefx,代码行数:10,代码来源:GregorianCalendarGetDaysInYear.cs

示例7: PosTest4

 public void PosTest4()
 {
     System.Globalization.Calendar kC = new KoreanCalendar();
     System.Globalization.Calendar gC = new GregorianCalendar();
     DateTime dateTime = new DateTime(_generator.GetInt64(-55) % (DateTime.MaxValue.Ticks + 1));
     dateTime = new GregorianCalendar().ToDateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0);
     int month = _generator.GetInt16(-55) % 12 + 1;
     int expectedValue = gC.GetDaysInYear(dateTime.Year, gC.GetEra(dateTime));
     int actualValue;
     actualValue = kC.GetDaysInYear(dateTime.Year + 2333, kC.GetEra(dateTime));
     Assert.Equal(expectedValue, actualValue);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:KoreanCalendarGetDaysInYear.cs

示例8: NegTest2

 public void NegTest2()
 {
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     int year;
     year = myCalendar.MinSupportedDateTime.Year - 100;
     Assert.Throws<ArgumentOutOfRangeException>(() =>
    {
        myCalendar.GetDaysInYear(year);
    });
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:GregorianCalendarGetDaysInYear.cs


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