Skip to content

Commit

Permalink
fix: culture must be the default culture provided by .NET (#278)
Browse files Browse the repository at this point in the history
Before the fix, local computer settings changes could affect the culture, decreasing the library's portability.
  • Loading branch information
Seddryck authored Jul 29, 2024
1 parent ea8b5a2 commit 6746695
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Expressif.Testing/Predicates/Text/MatchingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ public void MatchesDateTime_InvariantCultureTimeOnly_Valid()
public void MatchesTime_InvariantCulture_Success(object? value, bool expected)
=> Assert.That(new MatchesTime().Evaluate(value), Is.EqualTo(expected));

[Test]
[TestCase("25/12/2025 10:01:55", false)]
public void MatchesDateTime_AmericanCulture_Fail(object? value, bool expected)
=> Assert.That(new MatchesDateTime(() => "en-US").Evaluate(value), Is.EqualTo(expected));

[Test]
[TestCase("25/12/2025 10:01:55", true)]
public void MatchesDateTime_FrenchCulture_Success(object? value, bool expected)
=> Assert.That(new MatchesDateTime(() => "fr-FR").Evaluate(value), Is.EqualTo(expected));


[Test]
[TestCase("2022-11-02", false)]
[TestCase("2022-11-02 13:57:00", false)]
Expand Down
2 changes: 1 addition & 1 deletion Expressif/Predicates/Text/Matching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BaseTextPredicateMatching(Func<string> culture)
protected virtual CultureInfo GetCulture(string culture)
{
if (!string.IsNullOrEmpty(culture))
return (new CultureInfo(culture).Clone() as CultureInfo)!;
return new CultureInfo(culture, false);

var invariantCulture = (CultureInfo.InvariantCulture.Clone() as CultureInfo)!;
invariantCulture.DateTimeFormat.ShortDatePattern = "yyyy/MM/dd";
Expand Down

0 comments on commit 6746695

Please sign in to comment.