FixedHoliday(Int32, Int32, Boolean, String) Constructor
Construct a new holiday object that occurs on a fixed date. The holiday date can optionally be
adjusted to a Friday or Monday if it falls on a weekend.
Namespace: EWSoftware.PDIAssembly: EWSoftware.PDI (in EWSoftware.PDI.dll) Version: 2025.1.9.0
public FixedHoliday(
int month,
int day,
bool adjust,
string description
)
Public Sub New (
month As Integer,
day As Integer,
adjust As Boolean,
description As String
)
public:
FixedHoliday(
int month,
int day,
bool adjust,
String^ description
)
new :
month : int *
day : int *
adjust : bool *
description : string -> FixedHoliday
Parameters
- month Int32
- The month of the holiday.
- day Int32
- The day of the month on which it occurs.
- adjust Boolean
- Set to true to adjust date to the Friday or Monday if it falls on a weekend or
false to always keep it on the specified day of the month.
- description String
- A description of the holiday.
This example demonstrates the use of the holiday classes and their methods.
DateTime testDate;
int yearFrom = 1998, yearTo = 2006;
HolidayCollection holidays = new HolidayCollection();
holidays.AddFixed(1, 1, true, "New Year's Day");
holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 1, 0, "Martin Luther King Day");
holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 2, 0, "President's Day");
holidays.AddFloating(DayOccurrence.Last, DayOfWeek.Monday, 5, 0, "Memorial Day");
holidays.AddFixed(7, 4, true, "Independence Day");
holidays.AddFloating(DayOccurrence.First, DayOfWeek.Monday, 9, 0, "Labor Day");
holidays.AddFixed(11, 11, true, "Veteran's Day");
holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 0, "Thanksgiving Day");
holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 1, "Day After Thanksgiving");
holidays.AddFixed(12, 25, true, "Christmas Day");
Console.WriteLine("Holidays on file. Is Holiday should be true for all.");
foreach(Holiday hol in holidays)
Console.WriteLine("Holiday Date: {0:d} Is Holiday: {1} Description: {2}",
hol.ToDateTime(yearFrom), holidays.IsHoliday(hol.ToDateTime(yearFrom)),
hol.Description);
Console.WriteLine("Looking for holidays using the IsHoliday method");
testDate = new DateTime(yearFrom, 1, 1);
while(testDate.Year <= yearTo)
{
if(holidays.IsHoliday(testDate))
Console.WriteLine("Found holiday: {0:d}", testDate);
testDate = testDate.AddDays(1);
}
Console.WriteLine("Looking for holidays using HolidaysBetween");
var holidayDates = new HashSet<DateTime>(holidays.HolidaysBetween(yearFrom, yearTo));
if(holidayDates.Count != 0)
{
testDate = new DateTime(yearFrom, 1, 1);
while(testDate.Year <= yearTo)
{
if(holidayDates.Contains(testDate))
Console.WriteLine("Found holiday: {0:d} {1}", testDate,
holidays.HolidayDescription(testDate));
testDate = testDate.AddDays(1);
}
}
Dim testDate As DateTime
Dim holidayDates As HashSet(Of DateTime)
Dim yearFrom As Integer = 1998
Dim yearTo As Integer = 2006
Dim hol As Holiday
Dim holidays As New HolidayCollection()
holidays.AddFixed(1, 1, True, "New Year's Day")
holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 1, 0, "Martin Luther King Day")
holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 2, 0, "President's Day")
holidays.AddFloating(DayOccurrence.Last, DayOfWeek.Monday, 5, 0, "Memorial Day")
holidays.AddFixed(7, 4, True, "Independence Day")
holidays.AddFloating(DayOccurrence.First, DayOfWeek.Monday, 9, 0, "Labor Day")
holidays.AddFixed(11, 11, True, "Veteran's Day")
holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 0, "Thanksgiving Day")
holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 1, "Day After Thanksgiving")
holidays.AddFixed(12, 25, True, "Christmas Day")
Console.WriteLine("Holidays on file. Is Holiday should be true for all.")
For Each hol In holidays
Console.WriteLine("Holiday Date: {0:d} Is Holiday: {1} Description: {2}",
hol.ToDateTime(yearFrom), holidays.IsHoliday(hol.ToDateTime(yearFrom)),
hol.Description)
Next
Console.WriteLine("Looking for holidays using the IsHoliday method")
testDate = New DateTime(yearFrom, 1, 1)
Do While testDate.Year <= yearTo
If holidays.IsHoliday(testDate) = True Then
Console.WriteLine("Found holiday: {0:d}", testDate)
End If
testDate = testDate.AddDays(1)
Loop
Console.WriteLine("Looking for holidays using HolidaysBetween")
var holidayDates = new HashSet(Of DateTime)(holidays.HolidaysBetween(yearFrom, yearTo));
If holidayDates.Count != 0 Then
testDate = New DateTime(yearFrom, 1, 1)
Do While testDate.Year <= yearTo
If holidayDates.Contains(testDate) = True Then
Console.WriteLine("Found holiday: {0:d} {1}", testDate,
holidays.HolidayDescription(testDate))
End If
testDate = testDate.AddDays(1)
Loop
End If
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
ArgumentOutOfRangeException | An exception will be thrown if the month is not
between 1 and 12. |
ArgumentException | An exception will be thrown if the day is not valid for the
month. February 29th (leap year) is not accepted either. |