一个简单的工作日计算

一个简单的工作日计算:

function getWorkDay(dtBegin:TDateTime;IncDays:Integer):TDateTime;
const
  days: array[1..7] of string=('7','1','2','3','4', '5','6');
var
  week1:string;
  x:integer;
  holiday:TStrings;
begin
  //初始化节假日,
  holiday:=TStringList.Create;
  //TODO:从数据库中取,此为演示
  holiday.Add('2014-10-01');
  holiday.Add('2014-10-02');  //and so on ...
  try
    //日期
    x:=1;
    while (x<=IncDays) do
    begin
      //判断是否周末
      week1:=days[DayOfWeek(dtBegin)];
      //今日周几
      if (week1='6') or (week1='7') or (holiday.IndexOf(FormatDateTime('yyyy-mm-dd',dtBegin))>=0) then
      begin
        dtBegin:=IncDay(dtBegin,1);
        Continue;
      end
      else
      begin
        dtBegin:=IncDay(dtBegin,1);
        x:=x+1;
      end;
    end;
    Result:=dtBegin;
  finally
    holiday.Free;
  end;
end;

 

你可能感兴趣的:(工作)