Work Time Rules
- 6 minutes to read
The Gantt control allows you to specify work days, work hours, and holidays.
The Gantt stores its work time rules in the control’s WorkTimeRules collection. The following work time rules are available:
- Daily Rule (DailyRule)
- Weekly Rule (WeeklyRule)
- Monthly Rule (MonthlyRule)
- Yearly Rule (YearlyRule)
The following table lists common rule settings:
Property | Description |
---|---|
Specifies whether a day is a work day. | |
Recurrence | Provides a rule’s recurrence settings. Each rule type provides an individual set of recurrence settings. |
Provides settings for work time ranges. |
Daily Rule
The Daily class contains settings for a daily recurrence pattern.
Property | Description |
---|---|
Specifies the daily recurrence’s start date. | |
Specifies the daily recurrence’s end date. | |
Specifies how many times a daily rule occurs. | |
Specifies the daily recurrence’s interval. |
Work time patterns:
A work day is from 8 AM to 5 PM with an hour break (for a specified month).
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:DailyRule> <Recurrence Start="03/01/2019" End="03/31/2019" /> <WorkTimeRanges> <dx:WorkTimeRange Start="08:00" End="12:00" /> <dx:WorkTimeRange Start="13:00" End="17:00" /> </WorkTimeRanges> </dx:DailyRule> ... </WorkTimeRules> </dx:ASPxGantt>
In code:
DailyRule dailyRule1 = new DailyRule(); dailyRule1.Recurrence.Start = new DateTime(2019, 03, 01); dailyRule1.Recurrence.End = new DateTime(2019, 03, 31); dailyRule1.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(08,00,00), End=new TimeSpan(12,00,00)}, new WorkTimeRange(){ Start=new TimeSpan(13,00,00), End=new TimeSpan(17,00,00)}, }); Gantt.WorkTimeRules.Add(dailyRule1);
Each third day is a work day with a work shift from 10 AM to 10 PM.
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:DailyRule> <Recurrence Start="03/01/2019" Interval="3" /> <WorkTimeRanges> <dx:WorkTimeRange Start="10:00" End="22:00" /> </WorkTimeRanges> </dx:DailyRule> ... </WorkTimeRules> </dx:ASPxGantt>
In code:
DailyRule dailyRule1 = new DailyRule(); dailyRule1.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(10,00,00), End=new TimeSpan(22,00,00)} }); dailyRule1.Recurrence.Start = new DateTime(2019, 03, 01); dailyRule1.Recurrence.Interval = 3; Gantt.WorkTimeRules.Add(dailyRule1);
Weekly Rule
The Weekly class contains settings for a weekly recurrence pattern.
Property | Description |
---|---|
Specifies a day of the week to which the rule is applied. | |
Specifies the weekly recurrence’s start date. | |
Specifies the weekly recurrence’s end date. | |
Specifies how many times a weekly rule occurs. | |
Specifies the weekly recurrence’s interval. |
Work time patterns:
Fridays, Saturdays, and Sundays are weekend days.
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:WeeklyRule IsWorkDay="false"> <Recurrence DayOfWeek="Friday" /> </dx:WeeklyRule> <dx:WeeklyRule IsWorkDay="false"> <Recurrence DayOfWeek="Saturday" /> </dx:WeeklyRule> <dx:WeeklyRule IsWorkDay="false"> <Recurrence DayOfWeek="Sunday" /> </dx:WeeklyRule> </WorkTimeRules> </dx:ASPxGantt>
In code:
WeeklyRule weekRule1 = new WeeklyRule(); weekRule1.IsWorkDay = false; weekRule1.Recurrence.DayOfWeek = DayOfWeek.Friday; WeeklyRule weekRule2 = new WeeklyRule(); weekRule2.IsWorkDay = false; weekRule2.Recurrence.DayOfWeek = DayOfWeek.Saturday; WeeklyRule weekRule3 = new WeeklyRule(); weekRule3.IsWorkDay = false; weekRule3.Recurrence.DayOfWeek = DayOfWeek.Sunday; Gantt.WorkTimeRules.Add(weekRule1); Gantt.WorkTimeRules.Add(weekRule2); Gantt.WorkTimeRules.Add(weekRule3);
Monday to Wednesday – work days from 8 AM to 2 PM , Thursday to Friday – work days from 2 PM to 8 PM, Saturday and Sunday – weekend days.
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:WeeklyRule> <Recurrence DayOfWeek="Monday" /> <WorkTimeRanges> <dx:WorkTimeRange Start="08:00" End="14:00" /> </WorkTimeRanges> </dx:WeeklyRule> <dx:WeeklyRule> <Recurrence DayOfWeek="Tuesday" /> <WorkTimeRanges> <dx:WorkTimeRange Start="08:00" End="14:00" /> </WorkTimeRanges> </dx:WeeklyRule> <dx:WeeklyRule> <Recurrence DayOfWeek="Wednesday" /> <WorkTimeRanges> <dx:WorkTimeRange Start="08:00" End="14:00" /> </WorkTimeRanges> </dx:WeeklyRule> <dx:WeeklyRule> <Recurrence DayOfWeek="Thursday" /> <WorkTimeRanges> <dx:WorkTimeRange Start="14:00" End="20:00" /> </WorkTimeRanges> </dx:WeeklyRule> <dx:WeeklyRule> <Recurrence DayOfWeek="Friday" /> <WorkTimeRanges> <dx:WorkTimeRange Start="14:00" End="20:00" /> </WorkTimeRanges> </dx:WeeklyRule> <dx:WeeklyRule IsWorkDay="false"> <Recurrence DayOfWeek="Saturday" /> </dx:WeeklyRule> <dx:WeeklyRule IsWorkDay="false"> <Recurrence DayOfWeek="Sunday" /> </dx:WeeklyRule> </WorkTimeRules> </dx:ASPxGantt>
In code:
WeeklyRule weekRule1 = new WeeklyRule(); weekRule1.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(08,00,00), End=new TimeSpan(14,00,00)} }); weekRule1.Recurrence.DayOfWeek = DayOfWeek.Monday; WeeklyRule weekRule2 = new WeeklyRule(); weekRule2.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(08,00,00), End=new TimeSpan(14,00,00)} }); weekRule2.Recurrence.DayOfWeek = DayOfWeek.Tuesday; WeeklyRule weekRule3 = new WeeklyRule(); weekRule3.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(08,00,00), End=new TimeSpan(14,00,00)} }); weekRule3.Recurrence.DayOfWeek = DayOfWeek.Wednesday; WeeklyRule weekRule4 = new WeeklyRule(); weekRule4.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(14,00,00), End=new TimeSpan(20,00,00)} }); weekRule4.Recurrence.DayOfWeek = DayOfWeek.Thursday; WeeklyRule weekRule5 = new WeeklyRule(); weekRule5.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(14,00,00), End=new TimeSpan(20,00,00)} }); weekRule5.Recurrence.DayOfWeek = DayOfWeek.Friday; WeeklyRule weekRule6 = new WeeklyRule(); weekRule6.IsWorkDay = false; weekRule6.Recurrence.DayOfWeek = DayOfWeek.Saturday; WeeklyRule weekRule7 = new WeeklyRule(); weekRule7.IsWorkDay = false; weekRule7.Recurrence.DayOfWeek = DayOfWeek.Sunday; Gantt.WorkTimeRules.Add(weekRule1); Gantt.WorkTimeRules.Add(weekRule2); Gantt.WorkTimeRules.Add(weekRule3); Gantt.WorkTimeRules.Add(weekRule4); Gantt.WorkTimeRules.Add(weekRule5); Gantt.WorkTimeRules.Add(weekRule6); Gantt.WorkTimeRules.Add(weekRule7);
Monthly
The Monthly class contains settings for a monthly recurrence pattern.
Property | Description |
---|---|
Specifies whether the gantt calculates the rule by the day of the week. | |
Specifies a day. | |
Specifies a day of the week’s occurrence. | |
Specifies a day of the week to which the rule is applied. | |
Specifies the monthly recurrence’s start date. | |
Specifies the monthly recurrence’s end date. | |
Specifies how many times a monthly rule occurs. | |
Specifies the monthly recurrence’s interval. |
Work time patterns:
Every second Friday in a month has a different work time.
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:MonthlyRule> <Recurrence DayOfWeek="Thursday" DayOfWeekOccurrence="Second" CalculateByDayOfWeek="true" /> <WorkTimeRanges> <dx:WorkTimeRange Start="08:00" End="16:00" /> </WorkTimeRanges> </dx:MonthlyRule> </WorkTimeRules> </dx:ASPxGantt>
In code:
... MonthlyRule monthlyRule1 = new MonthlyRule(); monthlyRule1.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(08,00,00), End=new TimeSpan(16,00,00)} }); monthlyRule1.Recurrence.DayOfWeek = DayOfWeek.Thursday; monthlyRule1.Recurrence.DayOfWeekOccurrence = DayOfWeekMonthlyOccurrence.Second; monthlyRule1.Recurrence.CalculateByDayOfWeek = true; ... Gantt.WorkTimeRules.Add(monthlyRule1);
Every 10th of the month is a day off (for three months).
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:MonthlyRule IsWorkDay="false" > <Recurrence Day="10" OccurrenceCount="3" /> </dx:MonthlyRule> </WorkTimeRules> </dx:ASPxGantt>
In code:
... MonthlyRule monthlyRule1 = new MonthlyRule(); monthlyRule1.IsWorkDay = false; monthlyRule1.Recurrence.Day = 10; monthlyRule1.Recurrence.OccurrenceCount = 3; ... Gantt.WorkTimeRules.Add(monthlyRule1);
Yearly
The Yearly class contains settings for an yearly recurrence pattern.
Property | Description |
---|---|
Specifies whether the Gantt control applies the rule according to the day of the week. | |
Specifies a day. | |
Specifies a month. | |
Specifies a day of the week’s occurrence. | |
Specifies a day of the week to which the rule is applied. | |
Specifies the yearly recurrence’s start date. | |
Specifies the yearly recurrence’s end date. | |
Specifies how many times a yearly rule occurs. | |
Specifies the yearly recurrence’s interval. |
Work time patterns:
2-week holidays.
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:YearlyRule IsWorkDay="false"> <Recurrence Start="03/01/2019" End="03/15/2019" /> </dx:YearlyRule> </WorkTimeRules> </dx:ASPxGantt>
In code:
... YearlyRule yearlyRule1 = new YearlyRule(); yearlyRule1.IsWorkDay = false; yearlyRule1.Recurrence.Start = new DateTime(2019, 03, 01); yearlyRule1.Recurrence.End = new DateTime(2019, 03, 15); Gantt.WorkTimeRules.Add(yearlyRule1);
The working day before a holiday is shortened by one hour.
Declaratively:
<dx:ASPxGantt ID="Gantt" runat="server"...> ... <WorkTimeRules> <dx:YearlyRule IsWorkDay="false"> <Recurrence Day="14" Month="February" /> </dx:YearlyRule> <dx:YearlyRule IsWorkDay="false"> <Recurrence Day="13" Month="February" /> <WorkTimeRanges> <dx:WorkTimeRange Start="08:00" End="16:00" /> </WorkTimeRanges> </dx:YearlyRule> </WorkTimeRules> </dx:ASPxGantt>
In code:
... YearlyRule yearRule1 = new YearlyRule(); yearRule1.Recurrence.Day = 14; yearRule1.Recurrence.Month = Month.February; yearRule1.IsWorkDay = false; YearlyRule yearRule2 = new YearlyRule(); yearRule2.Recurrence.Day = 13; yearRule2.Recurrence.Month = Month.February; yearRule2.WorkTimeRanges.AddRange(new List<WorkTimeRange> { new WorkTimeRange(){ Start=new TimeSpan(08,00,00), End=new TimeSpan(16,00,00)} }); Gantt.WorkTimeRules.Add(yearRule1); Gantt.WorkTimeRules.Add(yearRule2);