本文整理汇总了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;
}
示例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;
}
示例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 ) );
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
});
}