Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 2.06 KB

README.md

File metadata and controls

43 lines (31 loc) · 2.06 KB

Relative Date

RelativeDate Logo

Build status Coverage Status Quality Gate NuGet

Installation

Via NuGet

PM> Install-Package RelativeDate

Usage

Sometimes you just need to know the date of the third sunday of a month, Relative Date has you covered.

For a given year and month Relative Date will find the First, Second, Third, Fouth and Last interval, where the interval is Mon-Sat, Day, WeekDay or WeekendDay.

DateTime firstMonday = new RelativeDate(2018, 6).First(RelativeDate.Interval.Monday);
Assert.AreEqual(new DateTime(2018, 6, 4), firstMonday);
// first Monday in June 2018 is the 4th

DateTime secondThursday = new RelativeDate(2018, 6).Second(RelativeDate.Interval.Thursday);
Assert.AreEqual(new DateTime(2018, 6, 14), secondThursday);
// second Thursday in June 2018 is the 14th

DateTime thirdDay = new RelativeDate(2018, 6).Third(RelativeDate.Interval.Day);
Assert.AreEqual(new DateTime(2018, 6, 3), thirdDay);
// third day in June 2018 is the 3rd (Duh)

DateTime fourthWeekDay = new RelativeDate(2018, 6).Fourth(RelativeDate.Interval.WeekDay);
Assert.AreEqual(new DateTime(2018, 6, 6), fourthWeekDay);
// fourth week day in June 2018 is the 6th (It's a Wednesday btw)

DateTime lastWeekEndDay = new RelativeDate(2018, 6).Last(RelativeDate.Interval.WeekendDay);
Assert.AreEqual(new DateTime(2018, 6, 30), lastWeekEndDay);
// last weekend day in June 2018 is the 30th (Saturday)