C# Library for representing and managing recurring intervals, suitable for calendaring functions.
- Daily (+days)
- Weekly (+dayOfWeek)
- BiWeekly / Fortnightly
- BiMonthly (+dayOfMonth)
- Monthly (+dayOfMonth)
- Quarterly (+dayOfQuarter)
- Annually (+dayOfYear)
- [FourFourFour] (#four-four-four) (+dayOfPeriod)
- FourFourFive (+dayOfPeriod)
Run the following command in the NuGet Package Manager console to install the library:
PM> Install-Package RecurringInterval
For more information, visit the Nuget RecurringInterval repository
var interval = Interval.Create(<Period>, <Date>, <Integer End Day>);
var nextInterval = interval.Next();
Interval.Create(Period.Daily, <start date>, <days>);
The date argument is always the start date. The interger argument is how many days in the interval.
var interval = Interval.Create(Period.Daily, new DateTime(2017,1,1), 2); //Interval has 2 days
Assert.AreEqual(1, interval.StartDate.Day);
Assert.AreEqual(2, interval.EndDate.Day);
Assert.AreEqual(2, interval.TotalDays);
var next = interval.Next();
Assert.AreEqual(3, next.StartDate.Day);
Assert.AreEqual(4, next.EndDate.Day);
Assert.AreEqual(2, next.TotalDays);
Interval.Create(Period.Weekly, <start date>, <day of week to end on>);
The interger is the day of the week to end on, can can be cast from the System.DayOfWeek
enum. The date argument is any date between the end date and the start date.
var interval = Interval.Create(Period.Daily, new DateTime(2017, 5, 2), (int)DayOfWeek.Monday /* 2 */);
Assert.AreEqual(new DateTime(2017, 5, 2) interval.StartDate);
Assert.AreEqual(new DateTime(2017, 5, 8), interval.EndDate);
Assert.AreEqual(7, interval.TotalDays);
var next = interval.Next();
Assert.AreEqual(new DateTime(2017, 5, 9) next.StartDate);
Assert.AreEqual(new DateTime(2017, 5, 15), next.EndDate);
Assert.AreEqual(7, next.TotalDays);
Interval.Create(Period.Daily, <start date>, <ignored>);
The date argument is always the start date. The interger argument is ignored.
Interval.Create(Period.BiMonthly, <start date>, <end day of month>);
This is the most complex, and follows the following conventions for the integer argument end date:
For periods ending on:
- 1st and 16th of each month: use 1 or 16
- 2nd and 17th of month: use 2 or 17
- 3rd and 18th of month: use 3 or 18
- 4th and 19th of month: use 4 or 19
- 5th and 20th of month: use 5 or 20
- 6th and 21st of month: use 6 or 21
- 7th and 22nd of month: use 7 or 22
- 8th and 23rd of month: use 8 or 23
- 9th and 34th of month: use 9 or 24
- 10th and 25th of month: use 10 or 25
- 11th and 26th of month: use 11 or 26
- 12th and 27th of month: use 12 or 27
- 13th and last day of month: use 13
- 14th and last day of month: use 14
- 15th and last day of month: use -1, 15 or 28+
Interval.Create(Period.Monthly, <start date>, <day of month to end on>);
Interval.Create(Period.Quarterly, <start date>, <day of quarter to end on>);
Interval.Create(Period.Annual, <start date>, <day of year to end on>);
See https://en.wikipedia.org/wiki/4%E2%80%934%E2%80%935_calendar for a definition.
Interval.Create(Period.FourFourFour, <start date>, <ignored>);
See https://en.wikipedia.org/wiki/4%E2%80%934%E2%80%935_calendar for a definition.
Interval.Create(Period.FourFourFive, <start date>, <ignored>);