Code Monkey home page Code Monkey logo

dates.recurring's Introduction

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

dates.recurring's People

Contributors

gavynriebau avatar ducka avatar seangwright avatar sagdelen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.