[Fact]
public void Test_TimeSpan()
{
// Arrange
const string expected = "{\"T\":\"PT36H\"}";
var timespan = new Wrapper(TimeSpan.FromHours(36));
// Act
var serialized = JsonSerializer.Serialize(timespan);
var actual = Encoding.UTF8.GetString(serialized);
// Assert
Assert.Equal(expected, actual);
}
public readonly struct Wrapper
{
public Wrapper(TimeSpan t)
{
T = t;
}
public TimeSpan T { get; }
}
According to ISO 8601 durations, this unit test should pass:
But it's failing with the message:
As I understand,
"1.12:00:00"
is not a valid ISO 8601 representation of a duration (i.e. C#'sTimeSpan
). Is there a bug inISO8601TimeSpanFormatter
?