mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 12:49:09 +02:00
* fixed range error in incmonth()
git-svn-id: trunk@6858 -
This commit is contained in:
parent
d3736f563f
commit
6eb320506b
@ -264,8 +264,8 @@ end;
|
|||||||
|
|
||||||
function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer = 1 ): TDateTime;
|
function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer = 1 ): TDateTime;
|
||||||
var
|
var
|
||||||
|
TempMonth, S: Integer;
|
||||||
Year, Month, Day : word;
|
Year, Month, Day : word;
|
||||||
S : Integer;
|
|
||||||
begin
|
begin
|
||||||
If NumberOfMonths>=0 then
|
If NumberOfMonths>=0 then
|
||||||
s:=1
|
s:=1
|
||||||
@ -273,13 +273,14 @@ begin
|
|||||||
s:=-1;
|
s:=-1;
|
||||||
DecodeDate(DateTime, Year, Month, Day);
|
DecodeDate(DateTime, Year, Month, Day);
|
||||||
inc(Year,(NumberOfMonths div 12));
|
inc(Year,(NumberOfMonths div 12));
|
||||||
inc(Month,(NumberOfMonths mod 12)-1); // Mod result always positive
|
TempMonth:=Month+(NumberOfMonths mod 12)-1;
|
||||||
if Month>11 then
|
if (TempMonth>11) or
|
||||||
|
(TempMonth<0) then
|
||||||
begin
|
begin
|
||||||
Dec(Month, S*12);
|
Dec(TempMonth, S*12);
|
||||||
Inc(Year, S);
|
Inc(Year, S);
|
||||||
end;
|
end;
|
||||||
Inc(Month); { Months from 1 to 12 }
|
Month:=TempMonth+1; { Months from 1 to 12 }
|
||||||
If (Day>MonthDays[IsLeapYear(Year)][Month]) then
|
If (Day>MonthDays[IsLeapYear(Year)][Month]) then
|
||||||
Day:=MonthDays[IsLeapYear(Year)][Month];
|
Day:=MonthDays[IsLeapYear(Year)][Month];
|
||||||
result := Frac(DateTime) + DoEncodeDate(Year, Month, Day);
|
result := Frac(DateTime) + DoEncodeDate(Year, Month, Day);
|
||||||
|
Loading…
Reference in New Issue
Block a user