Bug in function DateUtils.SameDateTime
Original Reporter info from Mantis: zoran
-
Reporter name: Zoran Vučenović
Original Reporter info from Mantis: zoran
- Reporter name: Zoran Vučenović
Description:
The documentation (https://www.freepascal.org/docs-html/current/rtl/dateutils/samedatetime.html) says:
Check whether two TDateTime values have the same date and time parts.
and
SameDateTime compares the date/time parts of two timestamps A and B and returns True if they are equal, False if they are not
This means that function should return True when two TDateTime values represent the same Date/time up to the millisecond resolution.
Here is how it is currently implemented:
Function SameDateTime(const A, B: TDateTime): Boolean;
begin
Result:=Abs(A-B)<OneMilliSecond;
end;
- if two DateTime values are closer than one millisecond they can still resolve to different millisecond (even different dates, when around midnight).
But, as currently implemented, the function returns True.
- when different DateTime values are close to zero, these can represent the same date/time 1899-12-30, 00:00:00:000, but the function returns False.
Steps to reproduce:
I'm attaching the program (command line program, as Lazarus project) which shows three examples with the bug:
- Example 1 - DateUtils.SameDateTime returns True, when two date time values are decoded to different millisecond values.
- Example 2 - DateUtils.SameDateTime returns True, but we have even different days here!
- Example 3 - DateUtils.SameDateTime returns False, when two date time values are decoded to same millisecond.
Additional information:
I'm attaching the patch.
Mantis conversion info:
- Mantis ID: 39023
- Build: 49516
- Version: 3.3.1
- Fixed in version: 3.2.2
- Fixed in revision: 49517 (#492a0ffc)
- Target version: 4.0.0