CompareDateTime gives bad result for negative values
Original Reporter info from Mantis: Blaazen @Blaazen
-
Reporter name: Vojtech Cihak
Original Reporter info from Mantis: Blaazen @Blaazen
- Reporter name: Vojtech Cihak
Description:
Function CompareDateTime(const A, B: TDateTime): TValueRelationship; from dateutils gives bad results for negative dates (the same day but another time).
Please see: http://www.lazarus.freepascal.org/index.php/topic,17039.msg93480/topicseen.html#new
There is some analysis and patch from another user.
Steps to reproduce:
program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, clocale, math, dateutils, sysutils;
var a,b :TDateTime;
R: TValueRelationship;
begin
a := EncodeDateTime (1899,3,5,22,1,1,1);
b := EncodeDateTime (1899,3,5,23,1,1,1);
WriteLn('a '+floattostr(a));
WriteLn('b '+floattostr(b));
R:= CompareDateTime(a,b);
if r=-1 then WriteLn (DateTimeToSTr (a) + ' is less than '+DateTimeToSTr (b));
if r=1 then WriteLn (DateTimeToSTr (a) + ' is greater than '+DateTimeToSTr (b));
end.
Mantis conversion info:
- Mantis ID: 22107
- OS: Linux
- Build: 21251
- Platform: amd64
- Version: 2.5.1
- Fixed in version: 3.1.1
- Fixed in revision: 35467 (#7ff70cbe)
- Target version: 3.2.0