unit DTCalc;
interface
uses
{$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
SysUtils, Classes;
type
TDTCalc = class(TComponent)
private
FStartTime, FEndTime: TDateTime;
FYears, FMonths, FDays, FHours, FMinutes, FSeconds, FMSeconds: LongInt;
procedure SetStartTime(Value: TDateTime);
procedure SetEndTime(Value: TDateTime);
procedure Calculate;
procedure SetNone(Value: LongInt);
public
property Years: LongInt read FYears;
property Months: LongInt read FMonths;
property Days: LongInt read FDays;
property Hours: LongInt read FHours;
property Minutes: LongInt read FMinutes;
property Seconds: LongInt read FSeconds;
property MSeconds: LongInt read FMSeconds;
published
property StartTime: TDateTime read FStartTime write SetStartTime;
property EndTime: TDateTime read FEndTime write SetEndTime;
end;
procedure Register;
implementation
procedure TDTCalc.SetStartTime(Value: TDateTime);
begin
FStartTime := Value;
Calculate;
end;
procedure TDTCalc.SetEndTime(Value: TDateTime);
begin
FEndTime := Value;
Calculate;
end;
procedure TDTCalc.Calculate;
var
e: Extended;
procedure Truncate(var Value: LongInt);
begin
try
Value := Trunc(e);
except
Value := -1;
end;
end;
begin
e := MSecsPerDay * (FEndTime - FStartTime);
Truncate(FMSeconds);
e := e / 1000;
Truncate(FSeconds);
e := e / 60;
Truncate(FMinutes);
e := e / 60;
Truncate(FHours);
e := e / 24;
Truncate(FDays);
FMonths := Trunc((FEndTime - FStartTime) / 30.4375);
FYears := Trunc((FEndTime - FStartTime) / 365.25);
end;
procedure TDTCalc.SetNone
begin {} end;
procedure Register;
begin
RegisterComponents('Xacker', [TDTCalc]);
end;
end.