Class Calendar
Namespace: Aspose.Tasks
Assembly: Aspose.Tasks.dll (25.4.0)
Represents a calendar used in a project.
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Calendar : ICalendar
Inheritance
Implements
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
How to create simple calendar from scratch.
// create empty calendar
Calendar calendar = new Calendar("New calendar");
// adds default working days (8 working hours from 9:00 to 17:00)
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday));
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday));
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday));
// create new new working day
WeekDay myWeekDay = new WeekDay(DayType.Thursday);
// Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(1, 1, 1, 6, 0, 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, 12, 0, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(1, 1, 1, 14, 0, 0, 0);
wt2.ToTime = new DateTime(1, 1, 1, 18, 0, 0, 0);
myWeekDay.WorkingTimes.Add(wt1);
myWeekDay.WorkingTimes.Add(wt2);
myWeekDay.DayWorking = true;
calendar.Days.Add(myWeekDay);
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Friday));
// adds weekend
calendar.Days.Add(new WeekDay(DayType.Saturday));
calendar.Days.Add(new WeekDay(DayType.Sunday));
[VB]
' create empty calendar
Dim calendar As Calendar = New Calendar("New calendar")
' adds default working days (8 working hours from 9:00 to 17:00)
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday))
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday))
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday))
' create new new working day
Dim myWeekDay As WeekDay = New WeekDay(DayType.Thursday)
' Sets working time. Only time part of DateTime is important
Dim wt1 As WorkingTime = New WorkingTime()
wt1.FromTime = New DateTime(1, 1, 1, 6, 0, 0, 0)
wt1.ToTime = New DateTime(1, 1, 1, 12, 0, 0, 0)
Dim wt2 As WorkingTime = New WorkingTime()
wt2.FromTime = New DateTime(1, 1, 1, 14, 0, 0, 0)
wt2.ToTime = New DateTime(1, 1, 1, 18, 0, 0, 0)
myWeekDay.WorkingTimes.Add(wt1)
myWeekDay.WorkingTimes.Add(wt2)
myWeekDay.DayWorking = True
calendar.Days.Add(myWeekDay)
calendar.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Friday))
' adds weekend
calendar.Days.Add(New WeekDay(DayType.Saturday))
calendar.Days.Add(New WeekDay(DayType.Sunday))
Remarks
Calendars are used to define standard working and non-working times. Projects must have one base calendar. Tasks and resources can have their own non-base calendars that are based on a base calendar.
Properties
BaseCalendar
Gets or sets the base calendar on which this calendar depends. Only applicable if the calendar is not a base calendar.
public Calendar BaseCalendar { get; set; }
Property Value
Exceptions
Gets CalendarExceptionCollection object. The collection of exceptions that is associated with the calendar.
public CalendarExceptionCollection Exceptions { get; }
Property Value
Guid
Gets calendar’s Guid.
public string Guid { get; }
Property Value
IsBaseCalendar
Gets a value indicating whether the calendar is a base calendar.
public bool IsBaseCalendar { get; }
Property Value
IsBaselineCalendar
Gets or sets a value indicating whether the calendar is a baseline calendar.
public bool IsBaselineCalendar { get; set; }
Property Value
Name
Gets or sets the name of the calendar.
public string Name { get; set; }
Property Value
Uid
Gets or sets the unique identifier of the calendar.
public int Uid { get; set; }
Property Value
WeekDays
Gets WeekDaysCollection for this calendar. The collection of weekdays that defines the calendar.
public WeekDayCollection WeekDays { get; }
Property Value
WorkWeeks
Gets WorkWeekCollections object. The collection of work weeks that is associated with the calendar.
public WorkWeekCollection WorkWeeks { get; }
Property Value
Methods
Delete()
Removes calendar from project.
public void Delete()
Equals(object)
Returns a value indicating whether this instance is equal to a specified object.
public override bool Equals(object obj)
Parameters
obj
object
The object to compare with this instance.
Returns
True if o is a Calendar that has the same Uid value as this instance; otherwise, false.
GetFinishDateByStartAndWork(DateTime, Duration)
Calculates the date when the specified amount of work time will pass according to the calendar.
public DateTime GetFinishDateByStartAndWork(DateTime start, Duration work)
Parameters
start
DateTime
Start date.
work
Duration
Work duration.
Returns
Finish date.
GetFinishDateByStartAndWork(DateTime, TimeSpan)
Calculates the date when the specified amount of work time will pass according to the calendar.
public DateTime GetFinishDateByStartAndWork(DateTime start, TimeSpan work)
Parameters
start
DateTime
Start date.
work
TimeSpan
Work duration.
Returns
Finish date.
GetHashCode()
Returns a hash code for the instance of the class.
public override int GetHashCode()
Returns
a hash code for this object.
GetIntersectionCalendar(Calendar, Calendar)
Gets Aspose.Tasks.ICalendar instance which can be used to perform calculations on the intersection of work schedules of 2 calendars.
public static ICalendar GetIntersectionCalendar(Calendar calendar1, Calendar calendar2)
Parameters
calendar1
Calendar
First calendar.
calendar2
Calendar
Second calendar.
Returns
Implementation of ICalendar interface.
Exceptions
When any of the arguments is null.
GetNextWorkingDayStart(DateTime)
Calculates next working day start for the specified date.
public DateTime GetNextWorkingDayStart(DateTime date)
Parameters
date
DateTime
The date to get next working day start for.
Returns
Next working day start System.DateTime.
GetPreviousWorkingDayEnd(DateTime)
Calculates the end of the previous working date from the specified date.
public DateTime GetPreviousWorkingDayEnd(DateTime date)
Parameters
date
DateTime
the date to calculate the previous working day end.
Returns
The end of the previous working day end
GetStartDateFromFinishAndDuration(DateTime, Duration)
Returns start date based on the specified finish date and duration.
public DateTime GetStartDateFromFinishAndDuration(DateTime finish, Duration duration)
Parameters
finish
DateTime
The specified finish date.
duration
Duration
The specified duration.
Returns
Calculated start date.
GetStartDateFromFinishAndDuration(DateTime, TimeSpan)
Returns start date based on specified finish date and duration.
public DateTime GetStartDateFromFinishAndDuration(DateTime finish, TimeSpan duration)
Parameters
finish
DateTime
The specified finish date.
duration
TimeSpan
The specified duration.
Returns
Calculated start date.
GetTaskFinishDateFromDuration(Task, TimeSpan)
Calculates the task finish date and time from its start date, split parts and the work duration.
public DateTime GetTaskFinishDateFromDuration(Task task, TimeSpan duration)
Parameters
task
Task
The task to calculate finish date for.
duration
TimeSpan
The duration to calculate.
Returns
Task’s finish date for the given start date and duration.
Remarks
Returns DateTime.MinValue if task is summary, null or its start date is not set.
GetWorkingHours(DateTime, DateTime)
Return WorkUnit - Start, Finish and Duration of working hours for the specified date time interval.
public WorkUnit GetWorkingHours(DateTime start, DateTime finish)
Parameters
start
DateTime
Start date of the interval.
finish
DateTime
Finish date of the interval.
Returns
Instance of Aspose.Tasks.WorkUnit class containing Start, Finish and Duration of working hours.
GetWorkingHours(DateTime)
Returns the amount of working hours at the specified date.
public TimeSpan GetWorkingHours(DateTime dt)
Parameters
dt
DateTime
The date to get working hours for.
Returns
Working hours at the specified date.
GetWorkingTimes(DateTime)
Returns Aspose.Tasks.WorkingTimeCollection of working times for the specified date.
public WorkingTimeCollection GetWorkingTimes(DateTime dt)
Parameters
dt
DateTime
The date to get working times for.
Returns
Collection of Aspose.Tasks.WorkingTime instances.
IsDayWorking(DateTime)
Determines whether the specified day is a working day according to the calendar.
public bool IsDayWorking(DateTime dt)
Parameters
dt
DateTime
The date to check whether the day is working.
Returns
True if the day is a working day.
Make24HourCalendar(Calendar)
Makes a given Calendar to be a 24Hour Calendar. 24Hours Calendar is a Calendar in which every day of week is working with Round-the-clock working hours.
public static Calendar Make24HourCalendar(Calendar calendar)
Parameters
calendar
Calendar
Calendar to make 24 Hours Calendar from.
Returns
24Hour Calendar.
MakeNightShiftCalendar(Calendar)
Makes a given Calendar as Night Shift Calendar.
public static Calendar MakeNightShiftCalendar(Calendar calendar)
Parameters
calendar
Calendar
Calendar to make Night Shift Calendar.
Returns
Night Shift Calendar.
MakeStandardCalendar(Calendar)
Creates default standard calendar.
public static Calendar MakeStandardCalendar(Calendar calendar)
Parameters
calendar
Calendar
Calendar to make standard calendar from.
Returns
Calendar with 5 working days (Monday-Friday) with working times 8-12 and 13-17.