dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

Incomplete documentation on DateTime.TryParseExact

Open Emberfire opened this issue 11 months ago • 1 comments

Type of issue

Missing information

Description

It seems the DateTime.TryParseExact method can throw a System.FormatException if the format provided is invalid. When tested in ASP.NET MVC 4.7.2, the following code:

DateTime.TryParseExact("01/10/2025", "a", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)

throws a FormatException with a stack trace:

Input string was not in a correct format
   at System.DateTimeFormat.GetRealFormat(String format, DateTimeFormatInfo dtfi)
   at System.DateTimeParse.ExpandPredefinedFormat(String format, DateTimeFormatInfo& dtfi, ParsingInfo& parseInfo, DateTimeResult& result)
   at System.DateTimeParse.DoStrictParse(String s, String formatParam, DateTimeStyles styles, DateTimeFormatInfo dtfi, DateTimeResult& result)
   at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTimeResult& result)
   at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTime& result)
   at System.DateTime.TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, DateTime& result)
   ...

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact?view=netframework-4.7.2#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-string()-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/DateTime.xml

Document Version Independent Id

2ba91f2f-bf41-7f7b-b0b3-64c4c0c932d9

Article author

@dotnet-bot

Emberfire avatar Jan 29 '25 10:01 Emberfire

@Emberfire thanks for filing the issue. Are you interested to submit a PR to fix it?

tarekgh avatar Mar 10 '25 19:03 tarekgh

Hey @tarekgh, noticed this has been inactive for a while. Mind if I create a PR?

casuffitsharp avatar Jun 25 '25 13:06 casuffitsharp

@casuffitsharp please go ahead and submit the PR and tag me there. Thanks for helping with this issue.

tarekgh avatar Jun 25 '25 14:06 tarekgh

@tarekgh Just to confirm: is the standard process to edit the xml files directly (manually), or is there a specific tool or local preview step I should be using?

casuffitsharp avatar Jun 25 '25 18:06 casuffitsharp

@casuffitsharp you just open a PR with the suggested changes, and we review and merge. You edit the doc manually and the PR will automatically create a link with the modification to confirm the visuals.

tarekgh avatar Jun 25 '25 19:06 tarekgh