Version: SonarLint 7.2.0.76298 for Visual Studio
This rule (Use a format provider when parsing date and time) is raised for the following snippet, which I am using to parse dates in ISO format (e.g. returned by Javascript’s Date.toISOString()
):
DateTime.TryParse(x, null, DateTimeStyles.RoundtripKind, out var v);
According the official documentation, DateTimeStyles.RoundTripKind
works as follows:
The DateTimeKind field of a date is preserved when a DateTime object is converted to a string using the “o” or “r” standard format specifier, and the string is then converted back to a DateTime object.
To me this seems to imply DateTimeStyles.RoundTripKind
expects a date formatted in one of the o
or r
formats, which means it does not care at all about the provided IFormatProvider
.
If this is indeed true it would make this specific case a false positive.