Class Calendar

Class Calendar

Namespace: Aspose.Tasks
Assembly: Aspose.Tasks.dll (25.2.0)

Represents a calendar used in a project.

[ClassInterface(ClassInterfaceType.AutoDual)]
public class Calendar

Inheritance

objectCalendar

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.

csharp
[C#]
// 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));

csharp [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

### <a id="Aspose_Tasks_Calendar_BaseCalendar"></a> BaseCalendar

Gets or sets the base calendar on which this calendar depends.
Only applicable if the calendar is not a base calendar.

```csharp
public Calendar BaseCalendar { get; set; }

Property Value

Calendar

Exceptions

Gets CalendarExceptionCollection object. The collection of exceptions that is associated with the calendar.

public CalendarExceptionCollection Exceptions { get; }

Property Value

CalendarExceptionCollection

Guid

Gets calendar’s Guid.

public string Guid { get; }

Property Value

string

IsBaseCalendar

Gets a value indicating whether the calendar is a base calendar.

public bool IsBaseCalendar { get; }

Property Value

bool

IsBaselineCalendar

Gets or sets a value indicating whether the calendar is a baseline calendar.

public bool IsBaselineCalendar { get; set; }

Property Value

bool

Name

Gets or sets the name of the calendar.

public string Name { get; set; }

Property Value

string

Uid

Gets or sets the unique identifier of the calendar.

public int Uid { get; set; }

Property Value

int

WeekDays

Gets WeekDaysCollection for this calendar. The collection of weekdays that defines the calendar.

public WeekDayCollection WeekDays { get; }

Property Value

WeekDayCollection

WorkWeeks

Gets WorkWeekCollections object. The collection of work weeks that is associated with the calendar.

public WorkWeekCollection WorkWeeks { get; }

Property Value

WorkWeekCollection

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

bool

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

DateTime

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

DateTime

Finish date.

GetHashCode()

Returns a hash code for the instance of the class.

public override int GetHashCode()

Returns

int

a hash code for this object.

GetNextWorkingDayStart(DateTime)

Calculates next working day start from the date.

public DateTime GetNextWorkingDayStart(DateTime date)

Parameters

date DateTime

The date to get next working day start for.

Returns

DateTime

Next working day start System.DateTime.

GetPreviousWorkingDayEnd(DateTime)

Calculates previous working date end from the specified date.

public DateTime GetPreviousWorkingDayEnd(DateTime date)

Parameters

date DateTime

the specified instance of System.DateTime struct.

Returns

DateTime

Previous working day start System.DateTime

GetStartDateFromFinishAndDuration(DateTime, Duration)

Returns StartDate based on specified FinishDate and Duration.

public DateTime GetStartDateFromFinishAndDuration(DateTime finish, Duration duration)

Parameters

finish DateTime

The specified finish date.

duration Duration

The specified work duration.

Returns

DateTime

Calculated StartDate.

GetStartDateFromFinishAndDuration(DateTime, TimeSpan)

Returns StartDate based on specified FinishDate and Duration.

public DateTime GetStartDateFromFinishAndDuration(DateTime finish, TimeSpan duration)

Parameters

finish DateTime

The specified finish date.

duration TimeSpan

The specified work duration.

Returns

DateTime

Calculated StartDate.

GetTaskFinishDateFromDuration(Task, TimeSpan)

Calculates the task finish date and time from its start date, split parts and the duration.

public DateTime GetTaskFinishDateFromDuration(Task task, TimeSpan duration)

Parameters

task Task

The task to get finish date for.

duration TimeSpan

The task duration to split on.

Returns

DateTime

Task’s finish date.

Remarks

Returns DateTime.MinValue if task is summary, null or its start date is not set.

GetWorkingHours(DateTime, DateTime)

Return working hours for the specified dates.

public WorkUnit GetWorkingHours(DateTime start, DateTime finish)

Parameters

start DateTime

Start date.

finish DateTime

Finish date.

Returns

WorkUnit

Working hours.

GetWorkingHours(DateTime)

Returns amount of working hours at the date.

public TimeSpan GetWorkingHours(DateTime dt)

Parameters

dt DateTime

The date to get working hours for.

Returns

TimeSpan

Working hours.

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

WorkingTimeCollection

List of Aspose.Tasks.WorkingTime.

IsDayWorking(DateTime)

Determines whether the day is working day.

public bool IsDayWorking(DateTime dt)

Parameters

dt DateTime

The date to check day is working for.

Returns

bool

True if the day is 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

Calendar

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

Calendar

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

Calendar with 5 working days (Monday-Friday) with working times 8-12 and 13-17.