* Fix bug ID #25177: wrong constant used for rounding

git-svn-id: trunk@34507 -
This commit is contained in:
michael 2016-09-11 09:38:47 +00:00
parent 8c63be40f9
commit 63d3df5642

View File

@ -442,6 +442,8 @@ uses sysconst;
const
TDateTimeEpsilon = 2.2204460493e-16;
HalfMilliSecond = OneMillisecond /2 ;
{ ---------------------------------------------------------------------
Auxiliary routines
@ -1281,49 +1283,49 @@ end;
Function YearsBetween(const ANow, AThen: TDateTime): Integer;
begin
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon)/ApproxDaysPerYear);
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond)/ApproxDaysPerYear);
end;
Function MonthsBetween(const ANow, AThen: TDateTime): Integer;
begin
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon)/ApproxDaysPerMonth);
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond)/ApproxDaysPerMonth);
end;
Function WeeksBetween(const ANow, AThen: TDateTime): Integer;
begin
Result:=Trunc(Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon) div 7;
Result:=Trunc(Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond) div 7;
end;
Function DaysBetween(const ANow, AThen: TDateTime): Integer;
begin
Result:=Trunc(Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon);
Result:=Trunc(Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond);
end;
Function HoursBetween(const ANow, AThen: TDateTime): Int64;
begin
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon)*HoursPerDay);
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond)*HoursPerDay);
end;
Function MinutesBetween(const ANow, AThen: TDateTime): Int64;
begin
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon)*MinsPerDay);
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond)*MinsPerDay);
end;
Function SecondsBetween(const ANow, AThen: TDateTime): Int64;
begin
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon)*SecsPerDay);
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond)*SecsPerDay);
end;
Function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;
begin
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+TDateTimeEpsilon)*MSecsPerDay);
Result:=Trunc((Abs(DateTimeDiff(ANow,AThen))+HalfMilliSecond)*MSecsPerDay);
end;
Procedure PeriodBetween(Const ANow, AThen: TDateTime; Out Years, months, days : Word);