Ovaj bug u DateUtils unitu mi nikako nije jasan. Ovakav previd ne bi dozvolio sebi ni neko ko je tek počeo da programira.
Code:
function IncHour(const AValue: TDateTime;
const ANumberOfHours: Int64): TDateTime;
begin
if AValue > 0 then
Result := ((AValue * HoursPerDay) + ANumberOfHours) / HoursPerDay
else
Result := ((AValue * HoursPerDay) - ANumberOfHours) / HoursPerDay;
end;
function IncHour(const AValue: TDateTime;
const ANumberOfHours: Int64): TDateTime;
begin
if AValue > 0 then
Result := ((AValue * HoursPerDay) + ANumberOfHours) / HoursPerDay
else
Result := ((AValue * HoursPerDay) - ANumberOfHours) / HoursPerDay;
end;
I onda ovakav kod postane problematičan:
Code:
var
Duration: TDateTime;
begin
Duration := 0;
if Duration > IncHour(0, 2) then
ShowMessage('Inc Error!');
if Duration < IncHour(0, -2) then
ShowMessage('Dec Error!');
end;
var
Duration: TDateTime;
begin
Duration := 0;
if Duration > IncHour(0, 2) then
ShowMessage('Inc Error!');
if Duration < IncHour(0, -2) then
ShowMessage('Dec Error!');
end;
A još ako duration nije jednostavno 0, nego neka vrednost izračunata na ko zna koji način, koju treba da uporediš sa nekom drugom vrednošću, razbiješ glavu pokušavajući da shvatiš zašto kod koji je radio na D2007, odjednom radi pogrešno...
Divno...
viking ®