Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Resolved an issue with List<TimeSpan> #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/Utf8Json/Formatters/DateTimeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ public TimeSpan Deserialize(ref JsonReader reader, IJsonFormatterResolver format
{
bool foundDot = false;
bool foundColon = false;
for (int j = i; j < str.Count; j++)
for (int j = i; j < to; j++)
{
if (array[j] == '.')
{
Expand Down
16 changes: 16 additions & 0 deletions tests/Utf8Json.Tests/DateAndTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ public void Misc()
}
}

[Fact]
public void ListOfTimespansShouldSerialize()
{
var data = new List<TimeSpan>
{
TimeSpan.FromHours(1),
TimeSpan.FromHours(5),
TimeSpan.FromHours(5),
TimeSpan.FromDays(1),
TimeSpan.FromDays(2)
};
var serialized = Utf8Json.JsonSerializer.ToJsonString(data);
var deSerialized = Utf8Json.JsonSerializer.Deserialize<List<TimeSpan>>(serialized);
var serialized2 = Utf8Json.JsonSerializer.ToJsonString(deSerialized);
serialized2.Is(serialized);
}

[Fact]
public void ShortFormat()
Expand Down