ScanDateTime issues in AM/PM mode
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
ScanDateTime converts a string to a date/time value according to a format mask string. AM/PM modifiers are allowed to take care of the 12-hour clock format.
In the convention that the time within the first hour after midnight/noon is named "12" rather than "0" (https://www.timeanddate.com/time/am-and-pm.html). A discussion in the forum (https://forum.lazarus.freepascal.org/index.php/topic,53235.msg393540.html) made clear that ScanDateTime does not follow this convention.
The attached patch fixes this issue. It also takes care of the case that an hour >=13 is specified in AM/PM mode.
Enclosed is a test program which covers a variety of cases.
Steps to reproduce:
Run the attached test program. It displays "ERROR" for the test times within the first hour after midnight/noon. After application of the patch, all tests are passed.
Additional information:
An EPS value is introduced to protect the numeric comparisons from floating point round-off errors. This value is assumed to be 1E-15 here. I am not sure whether this is the correct choice because FPC is used on a varietry of platforms which I could not test. Since ScanDateTime cannot detect time differences smaller than 1 ms due to the format mask string it is maybe wiser to set EPS to something like 0.1 ms = (0.1/(246060*1000) = 1E-9.
Mantis conversion info:
- Mantis ID: 38462
- Fixed in version: 3.3.1
- Fixed in revision: 48580 (#47be4583)
- Target version: 3.2.2