Regards - Hans
Code: Select all
Procedure TeeDateTimeIncrement( IsDateTime:Boolean;
Increment:Boolean;
var Value:Double;
Const AnIncrement:Double;
tmpWhichDateTime:TDateTimeStep);
var Year : Word;
Month : Word;
Day : Word;
Procedure DecMonths(HowMany:Word);
begin
Day:=1;
if Month>HowMany then Dec(Month,HowMany)
else
begin
Dec(Year);
Month:=12-(HowMany-Month);
end;
end;
Procedure IncMonths(HowMany:Word);
begin
Day:=1;
Inc(Month,HowMany);
if Month>12 then
begin
Inc(Year);
Month:=Month-12;
end;
end;
Procedure IncDecMonths(HowMany:Word);
begin
if Increment then IncMonths(HowMany)
else DecMonths(HowMany);
end;
{$ifdef HH_PATCH_TC_DATETIME}
VAR MinNewValue:double;
{$endif}
begin
if IsDateTime then
begin
DecodeDate(Value,year,month,day);
{$ifdef HH_PATCH_TC_DATETIME}
// This loop keeps adding the desired value until the
// AnIncrement value is reached. This avoids having too many
// date labels below a chart
if Increment then MinNewValue:=Value+AnIncrement
else MinNewValue:=Value-AnIncrement;
repeat
{$endif}
Case tmpWhichDateTime of
dtHalfMonth : Begin
if Day>15 then Day:=15
else
if Day>1 then Day:=1
else
begin
IncDecMonths(1);
Day:=15;
end;
end;
dtOneMonth : IncDecMonths(1);
dtTwoMonths : IncDecMonths(2);
dtThreeMonths : IncDecMonths(3);
dtFourMonths : IncDecMonths(4);
dtSixMonths : IncDecMonths(6);
dtOneYear : if Increment then Inc(year) else Dec(year);
else
begin
if Increment then Value:=Value+AnIncrement
else Value:=Value-AnIncrement;
Exit;
end;
end;
Value:=EncodeDate(year,month,day);
{$ifdef HH_PATCH_TC_DATETIME}
until (tmpWhichDateTime<dtOneYear)
or (Increment and (Value>=MinNewValue))
or (not Increment and (Value<=MinNewValue));
{$endif}
end
else
begin
if Increment then Value:=Value+AnIncrement
else Value:=Value-AnIncrement;
end;
end;