Incorrect result of YearsBetween()
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
YearsBetween(1956-12-01,2015-12-01) incorrectly returns 58, it shoud be 59.
Steps to reproduce:
program yearsdiff;
uses
SysUtils, DateUtils;
var
D1, D2: TDateTime;
begin
D1 := (EncodeDate(1956, 12, 1));
D2 := (EncodeDate(2015, 12, 1));
writeln('FPC: ',YearsBetween(D1, D2));
end.
It ouputs (win32 fpc 3.0.2RC1 and trunk):
FPC: 58
Additional information:
See related forum discussion: http://forum.lazarus.freepascal.org/index.php/topic,35432.0.html
For dates > 31-12-1899 a precise value can be returned that does not rely on ApproxDaysPerYear.
While one could debate that, since both dates have the same day and month, and therefore the last year counting "is not full", when it compares 1958-12-01 with 2016-12-01, it returns 58 as expected.
Also adding 1 hour to 2015-12-01 does not change the outcome.
Mantis conversion info:
- Mantis ID: 31233
- OS: Windows
- OS Build: Win7
- Platform: i386
- Fixed in version: 3.1.1
- Fixed in revision: 35423 (#dc500f72)
- Target version: 3.2.0