unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DateUtils, StdCtrls;
type
TForm2 =
class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TTimePeriod =
record
StartTimestamp : TDateTime;
EndTimestamp : TDateTime;
end;
TTimePeriodArray =
array of TTimePeriod;
var
Form2: TForm2;
implementation
{$R *.dfm}
function GetMaxTimeOverlaps(
const ATimePeriods : TTimePeriodArray): Integer;
var
TimeArray :
array [0..1439]
of Integer;
tp : TTimePeriod;
i : Integer;
n : Integer;
IndexStart, IndexEnd : Integer;
Maximum, Value: Integer;
begin
// Verteilung der Zeiten auf das Array
Maximum := 1;
for i := 1
to Length(ATimePeriods) - 1
do
begin
tp := ATimePeriods[i];
IndexStart := HourOf(
tp.StartTimestamp) * 60 + MinuteOf(
tp.StartTimestamp);
IndexEnd := HourOf(
tp.EndTimestamp) * 60 + MinuteOf(
tp.EndTimestamp);
for n := IndexStart
to IndexEnd
do
begin
Value := TimeArray[n];
Inc(Value);
if (Value > Maximum)
then
Maximum := Value;
TimeArray[n] := Value;
end;
end;
Result := Maximum - 1;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
TimeTabelle : TTimePeriodArray;
begin
SetLength(TimeTabelle, 5);
TimeTabelle[0].StartTimestamp := StrToDateTime('
21.03.2010 14:13');
TimeTabelle[0].EndTimestamp := StrToDateTime('
21.03.2010 14:33');
TimeTabelle[1].StartTimestamp := StrToDateTime('
22.03.2010 14:13');
TimeTabelle[1].EndTimestamp := StrToDateTime('
22.03.2010 14:33');
TimeTabelle[2].StartTimestamp := StrToDateTime('
22.03.2010 14:13');
TimeTabelle[2].EndTimestamp := StrToDateTime('
22.03.2010 14:33');
TimeTabelle[3].StartTimestamp := StrToDateTime('
22.03.2010 14:13');
TimeTabelle[3].EndTimestamp := StrToDateTime('
22.03.2010 14:33');
TimeTabelle[4].StartTimestamp := StrToDateTime('
22.03.2010 14:13');
TimeTabelle[4].EndTimestamp := StrToDateTime('
22.03.2010 14:33');
TimeTabelle[5].StartTimestamp := StrToDateTime('
22.03.2010 14:13');
TimeTabelle[5].EndTimestamp := StrToDateTime('
22.03.2010 14:33');
label1.Caption := IntToStr(GetMaxTimeOverlaps(TimeTabelle));
end;
end.