Retrieving Calendar Exceptions
Retrieving Calendar Exceptions
When working with project calendars in Aspose.Tasks for .NET, you may need to retrieve exception dates such as holidays, special workdays, or planned non-working periods. These exceptions are essential for accurately analyzing project schedules and durations.
The
Calendar
class provides access to calendar exceptions via the
Exceptions
property. This property returns a collection of
CalendarException
objects, each of which represents a specific exception period.
Each CalendarException
exposes properties such as:
FromDate
: the start date of the exception period.ToDate
: the end date of the exception period.DayWorking
: indicates whether the day is a working day.EnteredByOccurrences
: indicates whether the exception is recurring.
By iterating through the Exceptions
collection, you can examine or process all defined calendar exceptions in a project.
Example: Retrieving Calendar Exceptions
The following example demonstrates how to load a project and enumerate all calendar exceptions for its calendars.
1Project project = new Project("New Project.mpp");
2
3// Access calendars
4foreach (Calendar cal in project.Calendars)
5{
6 // Access calendar exceptions
7 foreach (CalendarException calExc in cal.Exceptions)
8 {
9 Console.WriteLine("From: " + calExc.FromDate.ToShortDateString());
10 Console.WriteLine("To: " + calExc.ToDate.ToShortDateString());
11 }
12}
Conclusion
Accessing calendar exceptions allows you to gain a complete understanding of a project’s working time configuration. This is especially useful when performing custom scheduling logic, generating reports, or validating that non-working periods are correctly defined.
For more advanced scenarios, consider also reading: