Skip to content

Need to know the first Thursday, second weekday, third weekend day or last day of a given month? This is for you.

License

Notifications You must be signed in to change notification settings

mattumotu/relativedate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Need to know the first Thursday, second weekday, third weekend day or last day of a given month? This is for you.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages