Skip to main content

Work Time Rules

  • 4 minutes to read

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

Run Demo: MVCxGantt - Work Time Schedule

To set up work time rules, populate the WorkTimeRules collection with the following objects:

The following table lists common rule settings:

Property

Description

IsWorkDay

Specifies whether a day is a work day.

Recurrence

Contains recurrence settings that depend on the rule type.

WorkTimeRanges

Contains settings for work time ranges.

Daily Rule

The Daily class contains settings for a daily recurrence pattern.

Property

Description

Start

Start date.

End

End date.

OccurrenceCount

Number of occurrences.

Interval

Interval between adjacent occurrences, in days.

Work time patterns:

  • In March of 2019, a work day is from 8:00 AM to 5:00 PM - with an hour break from noon to 1:00 PM.

    var dailyRule = new DailyRule();
    dailyRule.Recurrence.Start = new DateTime(2019, 03, 01);
    dailyRule.Recurrence.End = new DateTime(2019, 03, 31);
    dailyRule.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)},
    });
    settings.WorkTimeRules.Add(dailyRule);
    
  • In March of 2019, every third day is a work day - with a work shift from 10:00 AM to 10:00 PM.

    var dailyRule = new DailyRule();
    dailyRule.Recurrence.Start = new DateTime(2019, 03, 01);
    dailyRule.Recurrence.Interval = 3;
    dailyRule.WorkTimeRanges.AddRange(new List<WorkTimeRange>
    {
        new WorkTimeRange(){ Start=new TimeSpan(10,00,00), End=new TimeSpan(22,00,00)}
    });
    settings.WorkTimeRules.Add(dailyRule);
    

Weekly Rule

The Weekly class contains settings for a weekly recurrence pattern.

Property

Description

DayOfWeek

Day of the week.

Start

Start date.

End

End date.

OccurrenceCount

Number of occurrences.

Interval

Interval between adjacent occurrences, in weeks.

Work time patterns:

  • Fridays, Saturdays, and Sundays are non-working days.

    var weeklyRule1 = new WeeklyRule() { IsWorkDay = false };
    weeklyRule1.Recurrence.DayOfWeek = DayOfWeek.Friday;
    
    var weeklyRule2 = new WeeklyRule() { IsWorkDay = false };
    weeklyRule2.Recurrence.DayOfWeek = DayOfWeek.Saturday;
    
    var weeklyRule3 = new WeeklyRule() { IsWorkDay = false };
    weeklyRule3.Recurrence.DayOfWeek = DayOfWeek.Sunday;
    
    settings.WorkTimeRules.Add(weeklyRule1);
    settings.WorkTimeRules.Add(weeklyRule2);
    settings.WorkTimeRules.Add(weeklyRule3);
    
  • Monday to Wednesday – work days from 8:00 AM to 2:00 PM; Thursday to Friday – work days from 2:00 PM to 8:00 PM; Saturday and Sunday – non-work days.

    var weeklyRule1 = new WeeklyRule();
    weeklyRule1.Recurrence.DayOfWeek = DayOfWeek.Monday;
    weeklyRule1.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(08,00,00), 
        End=new TimeSpan(14,00,00)
    });
    
    var weeklyRule2 = new WeeklyRule();
    weeklyRule2.Recurrence.DayOfWeek = DayOfWeek.Tuesday;
    weeklyRule2.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(08,00,00), 
        End=new TimeSpan(14,00,00)
    });
    
    var weeklyRule3 = new WeeklyRule();
    weeklyRule3.Recurrence.DayOfWeek = DayOfWeek.Wednesday;
    weeklyRule3.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(08,00,00), 
        End=new TimeSpan(14,00,00)
    });
    
    var weeklyRule4 = new WeeklyRule();
    weeklyRule4.Recurrence.DayOfWeek = DayOfWeek.Thursday;
    weeklyRule4.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(14,00,00), 
        End=new TimeSpan(20,00,00)
    });
    
    var weeklyRule5 = new WeeklyRule();
    weeklyRule5.Recurrence.DayOfWeek = DayOfWeek.Friday;
    weeklyRule5.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(14,00,00), 
        End=new TimeSpan(20,00,00)
    });
    
    var weeklyRule6 = new WeeklyRule() { IsWorkDay = false };
    weeklyRule6.Recurrence.DayOfWeek = DayOfWeek.Saturday;
    
    
    var weeklyRule7 = new WeeklyRule() { IsWorkDay = false };
    weeklyRule7.Recurrence.DayOfWeek = DayOfWeek.Sunday;
    
    settings.WorkTimeRules.Add(weeklyRule1);
    settings.WorkTimeRules.Add(weeklyRule2);
    settings.WorkTimeRules.Add(weeklyRule3);
    settings.WorkTimeRules.Add(weeklyRule4);
    settings.WorkTimeRules.Add(weeklyRule5);
    settings.WorkTimeRules.Add(weeklyRule6);
    settings.WorkTimeRules.Add(weeklyRule7);
    

Monthly Rule

The Monthly class contains settings for a monthly recurrence pattern.

Property

Description

CalculateByDayOfWeek

Specifies whether the Gantt chart applies the rule to a day of the week (DayOfWeekOccurrence, DayOfWeek) or a specific day (Day).

Day

Day.

DayOfWeekOccurrence

Designates an occurrence interval for a specific day of the week.

DayOfWeek

Day of the week.

Start

Start date.

End

End date.

OccurrenceCount

Number of occurrences.

Interval

Interval between adjacent occurrences, in months.

Work time patterns:

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

    ...
    var monthlyRule = new MonthlyRule();
    monthlyRule.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(8,00,00), 
        End=new TimeSpan(16,00,00)
    });
    monthlyRule.Recurrence.DayOfWeek = DayOfWeek.Thursday;
    monthlyRule.Recurrence.DayOfWeekOccurrence = DayOfWeekMonthlyOccurrence.Second;
    monthlyRule.Recurrence.CalculateByDayOfWeek = true;
    ...
    settings.WorkTimeRules.Add(monthlyRule);
    
  • Every 10th of the month is a non-work day (for three months).

    ...
    var monthlyRule = new MonthlyRule() { IsWorkDay = false };
    monthlyRule.Recurrence.Day = 10;
    monthlyRule.Recurrence.OccurrenceCount = 3;
    ...
    settings.WorkTimeRules.Add(monthlyRule);
    

Yearly Rule

The Yearly class contains settings for a yearly recurrence pattern.

Property

Description

CalculateByDayOfWeek

Specifies whether the Gantt chart applies the rule to a day of the week (DayOfWeekOccurrence, DayOfWeek) or a specific day (Day, Month)

Day

Day.

Month

Month.

DayOfWeekOccurrence

Designates an occurrence interval for a specific day of the week.

DayOfWeek

Day of the week.

Start

Start date.

End

End date.

OccurrenceCount

Number of occurrences.

Interval

Interval between adjacent occurrences, in years.

Work time patterns:

  • 2-week holidays.

    ...
    var yearlyRule = new YearlyRule() { IsWorkDay = false };
    yearlyRule.Recurrence.Start = new DateTime(2019, 03, 01);
    yearlyRule.Recurrence.End = new DateTime(2019, 03, 15);    
    
    settings.WorkTimeRules.Add(yearlyRule);
    
  • The work day before a holiday is shortened by one hour.

    ...
    var yearlyRule1 = new YearlyRule() { IsWorkDay = false };
    yearlyRule1.Recurrence.Day = 14;
    yearlyRule1.Recurrence.Month = Month.February;
    
    var yearlyRule2 = new YearlyRule();
    yearlyRule2.Recurrence.Day = 13;
    yearlyRule2.Recurrence.Month = Month.February;
    yearlyRule2.WorkTimeRanges.Add(new WorkTimeRange() { 
        Start=new TimeSpan(8,00,00), 
        End=new TimeSpan(16,00,00)
    });
    
    settings.WorkTimeRules.Add(yearlyRule1);
    settings.WorkTimeRules.Add(yearlyRule2);