本文整理汇总了C#中System.DateTime.countNewYearBreaks方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.countNewYearBreaks方法的具体用法?C# DateTime.countNewYearBreaks怎么用?C# DateTime.countNewYearBreaks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.countNewYearBreaks方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: countExcludedItems
private static int countExcludedItems(DateTime startDate, DateTime endDate, TimeframeSymbol timeframe)
{
int weekends = 0;
int christmas = 0;
int newYears = 0;
int sign = (startDate.CompareTo(endDate) < 0 ? 1 : -1);
weekends = countWeekendItems(startDate, endDate, timeframe);
newYears = sign * startDate.countNewYearBreaks(endDate, false) * (dayUnitsForTimeframe(timeframe) + getTimeframeHolidayInactiveUnits(timeframe));
christmas = sign * startDate.countChristmas(endDate, false) * (dayUnitsForTimeframe(timeframe) + getTimeframeHolidayInactiveUnits(timeframe));
return (weekends + christmas + newYears);
}
示例2: countNewYearBreaks_if_dates_in_the_same_year_positive_difference_zero_is_returned
public void countNewYearBreaks_if_dates_in_the_same_year_positive_difference_zero_is_returned()
{
DateTime baseDate = new DateTime(2016, 1, 4);
DateTime comparedDate = new DateTime(2016, 1, 10);
Assert.AreEqual(0, baseDate.countNewYearBreaks(comparedDate, true));
}
示例3: addTimeUnits_days
private static DateTime addTimeUnits_days(DateTime date, int units)
{
int remainder = units % 5;
int newWeekDay = (int)date.DayOfWeek + remainder;
bool breakWeek = newWeekDay > 5 || newWeekDay <= 0;
int daysToAdd = (units / 5) * 7 + remainder + Math.Sign(units) * (breakWeek ? 2 : 0);
DateTime newDate = date.AddDays(daysToAdd);
//Include year breaks.
int yearBreaks = date.countNewYearBreaks(newDate, false);
int christmas = date.countChristmas(newDate, false);
if (yearBreaks + christmas > 0)
{
newDate = addTimeUnits_days(newDate, Math.Sign(units) * (yearBreaks + christmas));
}
//Check if the result date is not New Year nor Christmas.
while (newDate.DayOfWeek == DayOfWeek.Sunday || newDate.DayOfWeek == DayOfWeek.Saturday || newDate.DayOfYear == 1 || newDate.IsChristmas())
{
int sign = Math.Sign(units);
newDate = newDate.AddDays(sign);
}
return newDate;
}
示例4: countNewYearBreaks_correct_value_is_returned_for_positive_difference_including_weekends
public void countNewYearBreaks_correct_value_is_returned_for_positive_difference_including_weekends()
{
DateTime baseDate = new DateTime(2010, 12, 30);
DateTime comparedDate = new DateTime(2016, 1, 4);
Assert.AreEqual(6, baseDate.countNewYearBreaks(comparedDate, true));
}
示例5: DateTime
public void countNewYearBreaks_correct_value_is_returned_for_date_from_previous_year_NY_at_week_including_weekends()
{
DateTime baseDate = new DateTime(2016, 1, 4);
DateTime comparedDate = new DateTime(2015, 12, 30);
Assert.AreEqual(1, baseDate.countNewYearBreaks(comparedDate, true));
}
示例6: countNewYearBreaks_both_dates_are_weekend_newYears_weekend_included
public void countNewYearBreaks_both_dates_are_weekend_newYears_weekend_included()
{
DateTime baseDate = new DateTime(2012, 1, 1);
DateTime comparedDate = new DateTime(2017, 1, 1);
Assert.AreEqual(5, baseDate.countNewYearBreaks(comparedDate, true));
}
示例7: countNewYearBreaks_both_dates_are_newYears_one_of_them_weekend_weekends_included
public void countNewYearBreaks_both_dates_are_newYears_one_of_them_weekend_weekends_included()
{
DateTime baseDate = new DateTime(2016, 1, 1);
DateTime comparedDate = new DateTime(2017, 1, 1);
Assert.AreEqual(1, baseDate.countNewYearBreaks(comparedDate, true));
}