Skip to content

Commit

Permalink
Merge pull request #8 from PooryaCareExpert/main
Browse files Browse the repository at this point in the history
Allow years with 18xx
  • Loading branch information
jaime-olivares authored Nov 28, 2024
2 parents 3be9f59 + a5fd85a commit 889a44f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static string[] ExtractMessages(string messages)

public static DateTime? ParseDateTime(string dateTimeString, out TimeSpan offset, bool throwExeption = false)
{
var expr = @"^\s*((?:19|20)[0-9]{2})(?:(1[0-2]|0[1-9])(?:(3[0-1]|[1-2][0-9]|0[1-9])(?:([0-1][0-9]|2[0-3])(?:([0-5][0-9])(?:([0-5][0-9](?:\.[0-9]{1,4})?)?)?)?)?)?)?(?:([+-][0-1][0-9]|[+-]2[0-3])([0-5][0-9]))?\s*$";
var expr = @"^\s*((?:18|19|20)[0-9]{2})(?:(1[0-2]|0[1-9])(?:(3[0-1]|[1-2][0-9]|0[1-9])(?:([0-1][0-9]|2[0-3])(?:([0-5][0-9])(?:([0-5][0-9](?:\.[0-9]{1,4})?)?)?)?)?)?)?(?:([+-][0-1][0-9]|[+-]2[0-3])([0-5][0-9]))?\s*$";
var matches = Regex.Matches(dateTimeString, expr, RegexOptions.Singleline);

offset = new TimeSpan();
Expand Down
20 changes: 20 additions & 0 deletions test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,27 @@ public void ParseDateTimeOffset_WithException()
{
}
}

[DataTestMethod]
[DataRow("18151231")]
[DataRow("19151231")]
[DataRow("20151231")]
public void ParseDateTime_Year(string dateTimeString)
{
var date = MessageHelper.ParseDateTime(dateTimeString);
Assert.IsNotNull(date);
}

[DataTestMethod]
[DataRow("1701231")]
[DataRow("16151231")]
[DataRow("00001231")]
public void ParseDateTime_Year_Negative(string dateTimeString)
{
var date = MessageHelper.ParseDateTime(dateTimeString);
Assert.IsNull(date);
}

[TestMethod]
public void GetValueTest()
{
Expand Down

0 comments on commit 889a44f

Please sign in to comment.