Skip to content

Easily calculate the next recurrence for recurring dates using a fluent syntax

License

Notifications You must be signed in to change notification settings

mikehachen/Dates.Recurring

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dates.Recurring

Easily calculate the next time at which a recurring event occurs. Uses a fluent syntax.

Build status

Install

PM> Install-Package Dates.Recurring

Calculate the next occurrence of a recurring date.

// Daily recurrences
var daily = Recurs
	.Starting(new DateTime(2015, 1, 1))
    .Every(1)
    .Days()
    .Ending(new DateTime(2015, 1, 15))
    .Build();

daily.Next(new DateTime(2014, 7, 3));  // 2015/01/01
daily.Next(new DateTime(2015, 1, 1));  // 2015/01/02
daily.Next(new DateTime(2015, 1, 2));  // 2015/01/03
daily.Next(new DateTime(2015, 1, 15)); // null

// Weekly recurrences
var weekly = Recurs
    .Starting(new DateTime(2015, 1, 1))
    .Every(1)
    .Weeks()
    .OnDays(Day.TUESDAY | Day.FRIDAY)
    .Ending(new DateTime(2015, 2, 19))
    .Build();

weekly.Next(new DateTime(2014, 1, 1);  // 2015/01/02
weekly.Next(new DateTime(2015, 1, 2);  // 2015/01/06
weekly.Next(new DateTime(2014, 1, 6);  // 2015/01/09
weekly.Next(new DateTime(2014, 1, 9);  // 2015/01/13

// Monthly recurrences
var monthly = Recurs
    .Starting(new DateTime(2015, 1, 1))
    .Every(1)
    .Months()
    .OnDay(24)
    .Ending(new DateTime(2016, 2, 4))
    .Build();

monthly.Next(new DateTime(2014, 4, 8);	// 2015/01/24
monthly.Next(new DateTime(2015, 1, 24); // 2015/02/24
monthly.Next(new DateTime(2015, 2, 24); // 2015/03/24
monthly.Next(new DateTime(2015, 2, 10); // 2015/03/24

// Yearly recurrences
var yearly = Recurs
		.Starting(new DateTime(2015, 1, 1))
		.Every(1)
		.Years()
		.OnDay(24)
		.OnMonths(Month.JANUARY | Month.FEBRUARY | Month.AUGUST)
		.Ending(new DateTime(2020, 1, 1))
		.Build();

yearly.Next(new DateTime(2014, 1, 1));	// 2015/01/24
yearly.Next(new DateTime(2015, 1, 1)); 	// 2015/01/24
yearly.Next(new DateTime(2015, 1, 23)); // 2015/01/24
yearly.Next(new DateTime(2014, 1, 24)); // 2015/02/24
yearly.Next(new DateTime(2014, 2, 24)); // 2015/08/24

About

Easily calculate the next recurrence for recurring dates using a fluent syntax

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%