The date functions in u_dzVariantUtils do not agree on what can be converted. TryVar2DateTime (and Var2DateTimeEx, which is built on it, see [bugs:#65]) converts a string with TryStr2DateTime (Windows format, German format, ISO 8601), rejects a Boolean, and accepts a number only between 0001-01-01 and MaxDateTime. The others do not:
Var2DateTimeStr and Var2DateStr convert a string with the RTL's variant cast, which only knows the Windows format (plus a number in a string). So they reject the ISO format they produce themselves: a round trip through them fails.Var2DateStrEx uses Str2Date, which raises EConvertError instead of EVariantConvertError, and has no range check, so FormatDateTime raises for an out-of-range number.Measured with Delphi 12 and 2007, short date format dd/mm/yyyy:
| Variant | TryVar2DateTime | Var2DateTimeStr / Var2DateStr | Var2DateStrEx |
|---|---|---|---|
| '2026-10-14' | True | EVariantConvertError | 2026-10-14 |
| '14.10.2026' | True | EVariantConvertError | 2026-10-14 |
| '14.10.2026 13:45:00' | True | EVariantConvertError | EConvertError |
| '46309.5' | False | 2026-10-14 12:00:00 / 2026-10-14 | EConvertError |
| 'abc' | False | EVariantConvertError | EConvertError |
| True | False | 1899-12-29 | 1899-12-29 |
| 1e20 | False | EVariantConvertError | EIntOverflow (12), EInvalidOp (2007) |
Fix: build Var2DateTimeStr, Var2DateStr and Var2DateStrEx on TryVar2DateTime(..., ehNoException), so all date functions convert the same way and raise EVariantConvertError for a value that cannot be converted. This changes which strings Var2DateTimeStr and Var2DateStr accept: a number in a string would no longer be accepted.
Found by a code review of the fix for [bugs:#65].
Fixed in revision #2443