Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NewDateRegex in StringExtensions #1556 #1557

Merged
merged 2 commits into from May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/RestSharp/Extensions/StringExtensions.cs
Expand Up @@ -25,7 +25,7 @@ namespace RestSharp.Extensions
public static class StringExtensions
{
static readonly Regex DateRegex = new Regex(@"\\?/Date\((-?\d+)(-|\+)?([0-9]{4})?\)\\?/");
static readonly Regex NewDateRegex = new Regex(@"newDate\((-?\d+)*\)");
static readonly Regex NewDateRegex = new Regex(@"newDate\((-?\d+)\)");

static readonly Regex IsUpperCaseRegex = new Regex(@"^[A-Z]+$");

Expand Down
22 changes: 22 additions & 0 deletions test/RestSharp.Tests/JsonTests.cs
Expand Up @@ -116,6 +116,28 @@ public void Can_Deserialize_DateTimeOffset()
);
}

[Test]
public void Can_Deserialize_NewDateTime()
{
var payload = GetPayLoad<NewDateTimeTestStructure>("newdatetimes.json");

Assert.AreEqual(
new DateTime(2011, 6, 30, 8, 15, 46, 929, DateTimeKind.Utc),
payload.DateTime
);
}

[Test]
public void Can_Deserialize_Negative_NewDateTime()
{
var payload = GetPayLoad<NewDateTimeTestStructure>("newdatetimes.json");

Assert.AreEqual(
new DateTime(1969, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc),
payload.DateTimeNegative
);
}

[Test]
public void Can_Deserialize_Decimal_With_Four_Zeros_After_Floating_Point()
{
Expand Down
3 changes: 3 additions & 0 deletions test/RestSharp.Tests/RestSharp.Tests.csproj
Expand Up @@ -84,6 +84,9 @@
<None Update="SampleData\NestedListSample.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SampleData\newdatetimes.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SampleData\objectproperty.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
7 changes: 7 additions & 0 deletions test/RestSharp.Tests/SampleClasses/misc.cs
Expand Up @@ -222,6 +222,13 @@ public class Iso8601DateTimeTestStructure
public DateTime DateTimeWithOffset { get; set; }
}

public class NewDateTimeTestStructure
{
public DateTime DateTime { get; set; }

public DateTime DateTimeNegative { get; set; }
}

public class TimeSpanTestStructure
{
public TimeSpan Tick { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions test/RestSharp.Tests/SampleData/newdatetimes.json
@@ -0,0 +1,4 @@
{
"DateTime": "new Date(1309421746929)",
"DateTimeNegative": "new Date(-1)"
}