Skip to content

Commit

Permalink
CommonRegexes.Date: accept incomplete dates
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed May 1, 2024
1 parent 08adaed commit 30ffc9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions commonItems.UnitTests/CommonRegexesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,16 @@ public void DateRegexMatchesDates() {
}

[Fact]
public void DateRegexRequiresThreeSections() {
Assert.DoesNotMatch(CommonRegexes.Date, "1918.11");
Assert.DoesNotMatch(CommonRegexes.Date, "1918");
Assert.DoesNotMatch(CommonRegexes.Date, "");
public void DateRegexMatchesIncompleteDates() {
Assert.Matches(CommonRegexes.Date, "1918.11.");
Assert.Matches(CommonRegexes.Date, "1918.11");
Assert.Matches(CommonRegexes.Date, "1918.");
Assert.Matches(CommonRegexes.Date, "1918");

Assert.Matches(CommonRegexes.Date, "-1918.11.");
Assert.Matches(CommonRegexes.Date, "-1918.11");
Assert.Matches(CommonRegexes.Date, "-1918.");
Assert.Matches(CommonRegexes.Date, "-1918");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion commonItems/CommonRegexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static partial class CommonRegexes {
private static partial Regex GetFloatRegex();
[GeneratedRegex("^\"-?\\d+(.\\d+)?\"$")]
private static partial Regex GetQuotedFloatRegex();
[GeneratedRegex("^\\-?\\d+[.]\\d+[.]\\d+$")]
[GeneratedRegex("^-?\\d+([.]\\d+)?([.]\\d+)?\\.?$")]
private static partial Regex GetDateRegex();
[GeneratedRegex(@"^""[^\n\""]+""$")]
private static partial Regex GetQuotedStringRegex();
Expand Down

0 comments on commit 30ffc9d

Please sign in to comment.