Extension methods for creating chronology objects like TimeSpan
or DateTime
that read more natural.
Add the following extension methods on int
and double
that allow creating a TimeSpan
:
.Milliseconds()
.Seconds()
.Minutes()
.Hours()
.Days()
// ↓ Using traditional creation of TimeSpan
TimeSpan timeout = TimeSpan.FromSeconds(10);
TimeSpan timeout = 10.Seconds();
// ↑ Using the extension methods from this library
It is also possible to combine multiple extension methods:
TimeSpan timeout = 1.Minutes(30.Seconds());
Add extension methods on int
for each month that allow creating a DateTime
:
// ↓ Using traditional creation of DateTime
DateTime time = new DateTime(2024, 12, 24);
DateTime time = 24.December(2024);
// ↑ Using the extension methods from this library
It is also possible to specify a time:
DateTime time = 24.December(2024).At(18, 30);
It is also possible combine this with the TimeSpan
extensions:
DateTime time = 3.Hours().Before(25.December(2024));