41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using System;
|
|
using Xunit;
|
|
|
|
namespace BlazorApp.Tests
|
|
{
|
|
public class CalendarTests
|
|
{
|
|
[Fact]
|
|
public void TestParseDuration()
|
|
{
|
|
// 1 week
|
|
Assert.Equal(Data.Calendar.ParseDuration("P1W"), TimeSpan.FromDays(7));
|
|
|
|
// 1 week and 2 days
|
|
Assert.Equal(Data.Calendar.ParseDuration("P1W2D"), TimeSpan.FromDays(7 + 2));
|
|
|
|
// 1 day
|
|
Assert.Equal(Data.Calendar.ParseDuration("P1D"), TimeSpan.FromDays(1));
|
|
Assert.Equal(Data.Calendar.ParseDuration("-P1D"), TimeSpan.FromDays(-1));
|
|
|
|
// 1 day, 5 hours
|
|
Assert.Equal(Data.Calendar.ParseDuration("P1DT5H"), TimeSpan.FromHours(24 + 5));
|
|
|
|
// 5 hours
|
|
Assert.Equal(Data.Calendar.ParseDuration("PT5H"), TimeSpan.FromHours(5));
|
|
|
|
// 1 hours, 3 minutes, 1 second
|
|
Assert.Equal(Data.Calendar.ParseDuration("PT1H03M01S"), TimeSpan.FromSeconds(3600 + 3 * 60 + 1));
|
|
|
|
// 3 weeks, 4 days, 1 hour, 3 minutes, 1 second
|
|
Assert.Equal(
|
|
Data.Calendar.ParseDuration("P3W4DT1H03M01S"),
|
|
TimeSpan.FromSeconds(3600 + 3 * 60 + 1) + TimeSpan.FromDays(3 * 7 + 4)
|
|
);
|
|
Assert.Equal(
|
|
Data.Calendar.ParseDuration("-P3W4DT1H03M01S"),
|
|
-(TimeSpan.FromSeconds(3600 + 3 * 60 + 1) + TimeSpan.FromDays(3 * 7 + 4))
|
|
);
|
|
}
|
|
}
|
|
} |