Skip to main content

Work Time Rules

  • 6 minutes to read

The Gantt control allows you to specify work days, work hours, and holidays.

Online Demo: ASPxGantt - Work Time Schedule

The Gantt stores its work time rules in the control’s WorkTimeRules collection. The following work time rules are available:

The following table lists common rule settings:

Property

Description

IsWorkDay

Specifies whether a day is a work day.

Recurrence

Contains a rule’s recurrence settings. Each rule type contains an individual set of recurrence settings.

WorkTimeRanges

Contains settings for work time ranges.

Daily Rule

The Daily class contains settings for a daily recurrence pattern.

Property

Description

Start

Specifies the daily recurrence’s start date.

End

Specifies the daily recurrence’s end date.

OccurrenceCount

Specifies how many times a daily rule occurs.

Interval

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).

    In markup:

    <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.

    In markup:

    <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

DayOfWeek

Specifies a day of the week to which the rule is applied.

Start

Specifies the weekly recurrence’s start date.

End

Specifies the weekly recurrence’s end date.

OccurrenceCount

Specifies how many times a weekly rule occurs.

Interval

Specifies the weekly recurrence’s interval.

Work time patterns:

  • Fridays, Saturdays, and Sundays are weekend days.

    In markup:

    <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.

    In markup:

    <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

CalculateByDayOfWeek

Specifies whether the Gantt control calculates the rule by the day of the week.

Day

Specifies a day.

DayOfWeekOccurrence

Specifies a day of the week’s occurrence.

DayOfWeek

Specifies a day of the week to which the rule is applied.

Start

Specifies the monthly recurrence’s start date.

End

Specifies the monthly recurrence’s end date.

OccurrenceCount

Specifies how many times a monthly rule occurs.

Interval

Specifies the monthly recurrence’s interval.

Work time patterns:

  • Every second Friday in a month has a different work time.

    In markup:

    <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).

    In markup:

    <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 a yearly recurrence pattern.

Property

Description

CalculateByDayOfWeek

Specifies whether the Gantt control applies the rule according to the day of the week.

Day

Specifies a day.

Month

Specifies a month.

DayOfWeekOccurrence

Specifies a day of the week’s occurrence.

DayOfWeek

Specifies the day of the week to which the rule is applied.

Start

Specifies the yearly recurrence’s start date.

End

Specifies the yearly recurrence’s end date.

OccurrenceCount

Specifies how many times a yearly rule occurs.

Interval

Specifies the yearly recurrence’s interval.

Work time patterns:

  • Every year a day off is May 27.

    In markup:

    <dx:ASPxGantt ID="Gantt" runat="server"...>
        ...
        <WorkTimeRules> 
            <dx:YearlyRule IsWorkDay="false">
                <Recurrence Day="27" Month="May" />
            </dx:YearlyRule>
       </WorkTimeRules>
    </dx:ASPxGantt>
    

    In code:

    ...
    YearlyRule yearRule = new YearlyRule();
    yearRule.Recurrence.Day = 27;
    yearRule.Recurrence.Month = Month.May;
    yearRule.IsWorkDay = false;
    
    Gantt.WorkTimeRules.Add(yearRule);
    
  • The work day before a holiday is shortened by one hour.

    In markup:

    <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);
    
See Also