Skip to content

Extension methods for creating chronology objects like `TimeSpan` or `DateTime` that read more natural.

License

Notifications You must be signed in to change notification settings

aweXpect/aweXpect.Chronology

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aweXpect.Chronology

Nuget Build Quality Gate Status Coverage Mutation testing badge

Extension methods for creating chronology objects like TimeSpan or DateTime that read more natural.

TimeSpan

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());

DateTime

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));

About

Extension methods for creating chronology objects like `TimeSpan` or `DateTime` that read more natural.

Resources

License

Code of conduct

Stars

Watchers

Forks