[fpc-pascal] <time_fraction>Between bug?

Bee Jay bee.ography at gmail.com
Mon May 31 12:08:23 CEST 2010


> But if I changed the milisecond part of a or b or both to anything but 0 then the result is correct.

Correction... the bug arises NOT only if the msec part is 0. The bug arises if msec part of both variables are EQUAL. If they are different, at least 1 msec, then those functions produce correct result.

See how serious the effect cause by this little bug...

> uses
>  DateUtils;
> var
>  a,b: TDateTime;
>  i: integer;
> begin
>  a := EncodeDateTime(2010, 1, 1, 0, 0, 0, 0);
>  for i := 0 to 9 do
>  begin
>    b := EncodeDateTime(2010+i, 1, 1, 0, 0, 0, 0);
>    Writeln(YearsBetween(a,b):3);
>  end;
> end;


Please note that I'm using YearsBetween in the above test. I'm not talking about superb precision in msec. The workaround is pretty trivial. If it compares the date part, both should at least have 1 day difference. If it compares the time part, both should at least have 1 msec difference. But I haven't done a thorough test, I might left other effects behind.

I think it'd be nice if it's corrected right from the DateUtils itself. Should I report it as bug?

-Bee-




More information about the fpc-pascal mailing list