Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/RestSharp/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DateTime": "new Date(1309421746929)",
"DateTimeNegative": "new Date(-1)"
}