Skip to main content

How to Customize the Work Time for Each Day

A scheduler’s OptionsView.WorkStart and OptionsView.WorkFinish properties specify the work time common to all workdays (see the scheduler’s OptionsView.WorkDays property).

To display a flexible work schedule, use a scheduler’s OnIsWorkTime event. This event provides the ATime and AIsWork parameters that allow you to determine the time block to be drawn and specify whether it is displayed as a work time or not.

In the example, the TimeOf routine (from the cxDateUtils unit) is used to extract time value from the ATime argument.

// ...
uses
  cxDateUtils;
// ...
procedure TForm1.cxScheduler1IsWorkTime(Sender: TObject;
  AResource: TcxSchedulerStorageResourceItem; const ATime: TDateTime;
  var AIsWork: Boolean);
var
  ATimeOnly: TDateTime;
begin
  ATimeOnly := TimeOf(ATime);
  case DayOfWeek(ATime) of
    // Monday and Wednesday: 8:00 AM - 11:00 AM
    2, 4: AIsWork := (ATimeOnly >= EncodeTime(7, 59, 59, 0)) and (ATimeOnly <= EncodeTime(10, 59, 59, 0));
    // Tuesday and Thursday: 11:00 AM - 6:00 PM
    3, 5: AIsWork := (ATimeOnly >= EncodeTime(10, 59, 59, 0)) and (ATimeOnly <= EncodeTime(17, 59, 59, 0))
  // other days are free
  else 
    AIsWork := False;
  end;
end;

The following image shows the result:

See Also