Skip to content

Commit

Permalink
fix list - update comments in code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Apr 14, 2023
1 parent 348a514 commit 2afa140
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rules/S6580/csharp/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ include::../how.adoc[]
[source,csharp,diff-id=1,diff-type=noncompliant]
----
var dateTimeString = "4/12/2023 4:05:48 PM"; // This is an en-US format string - 12 of April 2023
var dateTimeObject = DateTime.Parse(dateTimeString); // In a machine with "CultureInfo.CurrentCulture" en-150 (English Europe), this is parsed as 4th of December
var dateTimeObject = DateTime.Parse(dateTimeString); // This is wrongly parsed as 4th of December, when it's read in a machine with "CultureInfo.CurrentCulture" en-150 (English Europe)
var dateTimeString2 = "4/13/2023 4:05:48 PM"; // This is an en-US format string - 13 of April 2023
var dateTimeObject2 = DateTime.Parse(dateTimeString2); // Runtime Error
var dateTimeObject2 = DateTime.Parse(dateTimeString2); // Runtime Error, when it's parsed in a machine with "CultureInfo.CurrentCulture" en-150 (English Europe).
var timeInSaudiArabia = new TimeOnly(16, 23).ToString(new CultureInfo("ar-SA"));
var timeObject = TimeOnly.Parse(timeInSaudiArabia); // Runtime Error
var timeObject = TimeOnly.Parse(timeInSaudiArabia); // Runtime Error, when it's parsed in a machine with "CultureInfo.CurrentCulture" en-150 (English Europe).
----

==== Compliant solution
Expand Down
1 change: 1 addition & 0 deletions rules/S6580/description.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ When converting a string representation of a date and time to a `DateTime` objec
If not provided, the method will use the machine's `CultureInfo`; if the given string does not follow it, you'll have an object that does not match the string representation or an unexpected runtime error.

This rule raises an issue for the following date and time string representation parsing methods:

* `DateTime.Parse`
* `DateTimeOffset.Parse`
* `DateOnly.Parse`
Expand Down

0 comments on commit 2afa140

Please sign in to comment.