ISO8601ToDate issue with fractional seconds
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
The function ISO8601ToDate of unit DateUtils converts an ISO8601 formatted date/time string to a TDateTime variable. According to specification (https://en.wikipedia.org/wiki/ISO_8601), "there is no limit on the number of decimal places for the decimal fraction" and the decimal mark can be "either a comma or a dot".
However, FPC accepts only 3 decimals places, and the decimal separator can only be a dot. Otherwise the function raises an exception.
Delphi accepts any count of decimals, but the decimal separatur must be a dot as well.
The attached patch fixes the issue.
Steps to reproduce:
Run the attached demo. It varies the number of decimal places and switches the decimal separator between dot and comma. If successful the converted TDateTime number is displayed, otherwise the word "ERROR".
Unpatched FPC displays "ERROR" except for the case with three decimal places and decimal dot. Delphi XE10.3 displays "ERROR" only in the decimal comma cases.
After applying the patch "ERROR" is not displayed any more.
Additional information:
See also forum discussion https://forum.lazarus.freepascal.org/index.php/topic,54890.0.html
According to the cited article it is also possible to specify date and time strings without the date and time separators (i.e. '20210606' instead of '2021-06-06', or '1310' instead of '13:10') - these variants will crash the conversion, too, but are not covered by the present patch.
Mantis conversion info:
- Mantis ID: 38968
- Fixed in version: 3.3.1
- Fixed in revision: 49624 (#4fac31d1)
- Monitored by: » @davidbannon (David)
- Target version: 4.0.0