本文整理汇总了C#中System.DateTime.IsHoliday方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.IsHoliday方法的具体用法?C# DateTime.IsHoliday怎么用?C# DateTime.IsHoliday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.IsHoliday方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_use_national_holidays_in_calulations
public void can_use_national_holidays_in_calulations()
{
DateTime nationalDay = new DateTime(2011, 6, 10);
Assert.IsFalse(nationalDay.IsWorkingDay(pt_ci));
Assert.IsTrue(nationalDay.IsHoliday(pt_ci));
}
示例2: can_use_christian_holidays_in_calulations
public void can_use_christian_holidays_in_calulations()
{
DateTime corpus = new DateTime(2010, 12, 8);
Assert.IsFalse(corpus.IsWorkingDay(pt_ci));
Assert.IsTrue(corpus.IsHoliday(pt_ci));
}
示例3: picks_a_holiday_when_two_holidays_occur_on_the_same_date
public void picks_a_holiday_when_two_holidays_occur_on_the_same_date()
{
/* In 2005, Ascension day was on the fifth of May. That year, the fifth of may was
* also a national public holiday (liberation day). The holiday picker should not
* fail, but it is arbritrary which one of the holidays it should return, so either
* one is OK. HolidayStrategyBase.BuildObservancesMap should survive this.
*/
var inTheNetherlands = new WorkingDayCultureInfo("nl-NL");
var fifthOfMay = new DateTime(2005, 5, 5);
Assert.That(fifthOfMay.IsHoliday(inTheNetherlands));
}
示例4: can_provide_custom_locator_dayOfWeek_strategy
public void can_provide_custom_locator_dayOfWeek_strategy()
{
var mockDayOfWeekStartegy = Substitute.For<IWorkingDayOfWeekStrategy>();
mockDayOfWeekStartegy.IsWorkingDay(Arg.Any<DayOfWeek>()).Returns(false);
WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo()
{
LocateWorkingDayOfWeekStrategy = (n) => { return mockDayOfWeekStartegy; }
};
DateTime aThursday = new DateTime(2011, 5, 12);
Assert.IsFalse(aThursday.IsWorkingDay(workingdayCultureInfo));
Assert.IsFalse(aThursday.IsHoliday(workingdayCultureInfo));
mockDayOfWeekStartegy.Received().IsWorkingDay(aThursday.DayOfWeek);
}
示例5: can_provide_custom_locator_holiday_dayOfWeek_strategy
public void can_provide_custom_locator_holiday_dayOfWeek_strategy()
{
var mockHolidayStrategy = Substitute.For<IHolidayStrategy>();
mockHolidayStrategy.IsHoliDay(Arg.Any<DateTime>()).Returns(true);
var mockDayOfWeekStartegy = Substitute.For<IWorkingDayOfWeekStrategy>();
mockDayOfWeekStartegy.IsWorkingDay(Arg.Any<DayOfWeek>()).Returns(true);
WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo()
{
LocateHolidayStrategy = (n) => { return mockHolidayStrategy; },
LocateWorkingDayOfWeekStrategy = (n) => { return mockDayOfWeekStartegy; }
};
DateTime marchFirst = new DateTime(1991, 3, 1);
Assert.IsTrue(marchFirst.IsHoliday(workingdayCultureInfo));
Assert.IsFalse(marchFirst.IsWorkingDay(workingdayCultureInfo));
mockHolidayStrategy.Received().IsHoliDay(marchFirst);
mockDayOfWeekStartegy.Received().IsWorkingDay(marchFirst.DayOfWeek);
}
示例6: Main
static void Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR");
//Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
//Adicionando dias, contemplando apenas os dias úteis.
DateTime data = DateTime.Now.AddWorkDays(3);
//Adicionando dias, contemplando apenas dias úteis e definindo uma condição
//que determina se o dia inicial deve estar contemplado no cálculo.
//DateTime data = DateTime.Now.AddWorkDays(3, d => d.Hour > 12);
//Verificando se é ou não feriado.
DateTime temp = new DateTime(2008, 12, 25);
Console.WriteLine(temp.IsHoliday());
}
示例7: BuildDaysForMonthViewModel
private IEnumerable<DayViewModel> BuildDaysForMonthViewModel(int year, int month) {
var daysInMonth = GregorianCalendar.GetDaysInMonth(year, month);
for (int i = 1; i <= daysInMonth; i++) {
var day = new DateTime(year, month, i);
yield return new DayViewModel {
DayText = i.ToString(),
IsWorkingDay = day.IsWorkingDay(workingdayCultureInfo),
IsHoliday = day.IsHoliday(workingdayCultureInfo)
};
}
}
示例8: Fill
public void Fill() {
if (IsDone()) {
ShowFairness();
if (!FairEnough()) return;
ShowResult();
return;
}
var currentDate = new DateTime(Year, Month, GetFirstDayToFill());
var erTireness = 10;
var wardTireness = 5;
var OPDTireness = 2;
if (currentDate.IsHoliday()) {
erTireness = (erTireness * 3) / 2;
wardTireness = (wardTireness * 3) / 2;
}
var wayne = new Wayne(currentDate);
var rnd = new Random();
var doctorListCopy = _doctorList
.Where(x => !x.AbsenceList.Contains(currentDate))
.Where(x => !x.AmInWayneMoreThanTwoConsecutiveDays(currentDate))
.OrderBy(x => (x.ERWayne.Count() + x.WardWayne.Count() + x.OPDWayne.Count()) / x.Factor)
.ThenBy(x => x.Tireness / x.Factor)
.ThenBy(x => rnd.Next())
.Take(currentDate.NeedOPD() ? 4 : 3)
.ToList();
foreach (var erDoctor in doctorListCopy.Where(d => d.AmIOKForERThisDay(currentDate))) {
wayne.ERDoctor = erDoctor;
erDoctor.ERWayne.Add(currentDate);
erDoctor.Tireness += erTireness;
foreach (var wardDoctor in doctorListCopy.Where(d => d != erDoctor && d.AmIOKForWardThisDay(currentDate))) {
wayne.WardDoctor = wardDoctor;
wardDoctor.WardWayne.Add(currentDate);
wardDoctor.Tireness += wardTireness;
if (!currentDate.NeedOPD()) {
var wayneTableCopy = Copy();
if (wayneTableCopy.AddWayneIfAcceptable(wayne)) {
wayneTableCopy.Fill();
}
}
else {
foreach (var OPDDoctor in doctorListCopy.Where(d => d != erDoctor && d != wardDoctor)) {
wayne.OPDDoctor = OPDDoctor;
OPDDoctor.OPDWayne.Add(currentDate);
OPDDoctor.Tireness += OPDTireness;
var wayneTableCopy = Copy();
if (wayneTableCopy.AddWayneIfAcceptable(wayne)) {
wayneTableCopy.Fill();
}
OPDDoctor.Tireness -= OPDTireness;
OPDDoctor.OPDWayne.Remove(currentDate);
}
}
wardDoctor.Tireness -= wardTireness;
wardDoctor.WardWayne.Remove(currentDate);
}
erDoctor.Tireness -= erTireness;
erDoctor.ERWayne.Remove(currentDate);
}
}
示例9: IsHoliday_WithHolidayDate_ExpectTrue
public void IsHoliday_WithHolidayDate_ExpectTrue(
int year,
int month,
int day,
string expectedHolidayName)
{
// Arrange
DateTimeExtensions.MinValid = new DateTime(year, 1, 1);
DateTimeExtensions.MaxValid = new DateTime(year, 12, 31);
AddHolidays(DateTimeExtensions.Holidays);
var classUnderTest = new DateTime(year, month, day, 23, 53, 59);
var holiday = DateTimeExtensions.Holidays
.Where(e => e.Name == expectedHolidayName)
.Single();
Assert.AreEqual(holiday.Observed, classUnderTest.Date);
// Act
var actual = classUnderTest.IsHoliday();
// Assert
Assert.AreEqual(true, actual);
}
示例10: IsHoliday_WithDateAfterMaxValid_ExpectArgumentOutOfRangeException
public void IsHoliday_WithDateAfterMaxValid_ExpectArgumentOutOfRangeException(
int year,
int month,
int day,
string expectedMessage)
{
// Arrange
DateTimeExtensions.MinValid = new DateTime(2010, 1, 1);
DateTimeExtensions.MaxValid = new DateTime(2010, 12, 31);
var classUnderTest = new DateTime(year, month, day, 23, 53, 59);
// Act
TestDelegate act = () => classUnderTest.IsHoliday();
// Assert
var result = Assert.Throws<ArgumentOutOfRangeException>(act);
Assert.AreEqual(expectedMessage, result.Message);
}
示例11: IsHoliday_WithNonHolidayDate_ExpectFalse
public void IsHoliday_WithNonHolidayDate_ExpectFalse(
int year,
int month,
int day)
{
// Arrange
DateTimeExtensions.MinValid = new DateTime(year, 1, 1);
DateTimeExtensions.MaxValid = new DateTime(year, 12, 31);
AddHolidays(DateTimeExtensions.Holidays);
var classUnderTest = new DateTime(year, month, day, 23, 53, 59);
var holiday = DateTimeExtensions.Holidays
.Where(e => e.Observed == classUnderTest.Date)
.FirstOrDefault();
Assert.IsNull(holiday);
// Act
var actual = classUnderTest.IsHoliday();
// Assert
Assert.AreEqual(false, actual);
}