Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1080 → Rev 1081

/Delphi/akTimeLog/Source/LogInfoUnit.pas
0,0 → 1,142
// akTimeLog v3.0
// Copyright (c) 1999-2000 Anatoli Klassen
unit LogInfoUnit;
 
interface
 
type
TInfoType = (itTotal, itYear, itMonth, itDay, itTime);
 
TLogInfo = class
private
FStart, FStop, FDuration : TDateTime;
FYear, FMonth, FDay : longint;
FInfoType : TInfoType;
procedure SetStart(Start : TDateTime);
procedure SetStop(Stop : TDateTime);
procedure SetDuration(Duration : TDateTime);
procedure Decode;
function FullTimeToStr(DateTime : TDateTime) : string;
function ShortTimeToStr(DateTime : TDateTime) : string;
function TimeToString : string;
function DateToString : string;
function MonthToStr : string;
public
property Start : TDateTime read FStart write SetStart;
property Stop : TDateTime read FStop write SetStop;
property Duration : TDateTime read FDuration write SetDuration;
property Year : longint read FYear;
property Month : longint read FMonth;
property Day : longint read FDay;
property InfoType : TInfoType read FInfoType write FInfoType;
constructor Create(InfoType : TInfoType; Start, Stop : TDateTime);
procedure AddTime(ATime : TDateTime);
function ToString : string;
end;
 
implementation
 
uses SysUtils;
 
//= TLogInfo ===================================================================
 
constructor TLogInfo.Create(InfoType : TInfoType; Start, Stop : TDateTime);
begin
inherited Create;
FInfoType := InfoType;
FStart := Start;
FStop := Stop;
FDuration := Stop - Start;
Decode;
end;
 
procedure TLogInfo.SetStart(Start : TDateTime);
begin
FStart := Start;
FDuration := Stop - Start;
Decode;
end;
 
procedure TLogInfo.SetStop(Stop : TDateTime);
begin
FStop := Stop;
FDuration := Stop - Start;
end;
 
procedure TLogInfo.SetDuration(Duration : TDateTime);
begin
FDuration := Duration;
FStop := FStart + FDuration;
end;
 
procedure TLogInfo.AddTime(ATime : TDateTime);
begin
Duration := Duration + ATime;
end;
 
procedure TLogInfo.Decode;
var
Y, M, D : word;
 
begin
DecodeDate(FStart, Y, M, D);
FYear := Y;
FMonth := M;
FDay := D;
end;
 
function TLogInfo.FullTimeToStr(DateTime : TDateTime) : string;
var
Hours : longint;
 
begin
Hours := Trunc(DateTime * 24);
Result := Format('%d:%.2d', [Hours, Round((DateTime-Hours/24)*60)]);
end;
 
function TLogInfo.ShortTimeToStr(DateTime : TDateTime) : string;
begin
Result := TimeToStr(DateTime-Trunc(DateTime));
Result := Copy(Result, 0, Length(Result) - 3);
end;
 
function TLogInfo.TimeToString : string;
begin
Result := ShortTimeToStr(FStart) + ' - ' + ShortTimeToStr(FStop);
end;
 
function TLogInfo.DateToString : string;
begin
Result := DateToStr(FStart) + ' -> ' + FullTimeToStr(FDuration);
end;
 
function TLogInfo.MonthToStr : string;
const
MonthNames : array[1..12] of string = (
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
);
 
begin
Result := MonthNames[FMonth] + ' ' + IntToStr(FYear);
end;
 
function TLogInfo.ToString : string;
begin
case FInfoType of
itTotal :
Result := 'From ' + DateToStr(FStart) + ' to ' + DateToStr(FStop)
+ ' -> ' + FullTimeToStr(FDuration);
itYear :
Result := IntToStr(FYear) + ' -> ' + FullTimeToStr(FDuration);
itMonth :
Result := MonthToStr + ' -> ' + FullTimeToStr(FDuration);
itDay:
Result := DateToString;
else
Result := TimeToString;
end;
end;
 
end.