helper-dates 0.0.5

.NET Standard 2.0
Install-Package helper-dates -Version 0.0.5
dotnet add package helper-dates --version 0.0.5
<PackageReference Include="helper-dates" Version="0.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add helper-dates --version 0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: helper-dates, 0.0.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install helper-dates as a Cake Addin
#addin nuget:?package=helper-dates&version=0.0.5

// Install helper-dates as a Cake Tool
#tool nuget:?package=helper-dates&version=0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

jwPro Date Helpers

This project contains of number of date related helper functions and extension methods.

Current primary functions:

  • identify special dates or holidays
  • business related functions

To use helper functions:

  1. Add a reference helper-dates
  2. Add the namespace directive:
using jwpro.DateHelper.Enums;
using jwpro.DateHelper.Helpers;
  1. Call methods using the SpecialDateHelper static class
  • GetChristmasDay
  • GetChristmasEve
  • GetColumbusDay
  • GetIndependenceDay
  • GetLaborDay
  • GetMartinLutherKingJrDay
  • GetMemorialDay
  • GetNewYearsDay
  • GetNewYearsEve
  • GetPresidentsDay
  • GetSpecialDate
  • GetThanksgivingDay
  • GetThanksgivingDayAfter
  • GetVeteransDay
  • IsChristmasDay
  • IsChristmasEve
  • IsColumbusDay
  • IsIndependenceDay
  • IsLaborDay
  • IsMartinLutherKingJrDay
  • IsMemorialDay
  • IsNewYearsDay
  • IsNewYearsEve
  • IsPresidentsDay
  • IsSpecialDate
  • IsThanksgivingDay
  • IsThanksgivingDayAfter
  • IsVeteransDay
  • IsWeekday
  • IsWeekend

To use extension methods:

  1. Add a reference helper-dates
  2. Add the namespace directive:
using jwpro.DateHelper.Enums;
using jwpro.DateHelper.Extensions;
  1. Call extension methods from any DataTime variable
  • IsChristmasDay
  • IsChristmasEve
  • IsColumbusDay
  • IsIndependenceDay
  • IsLaborDay
  • IsMartinLutherKingJrDay
  • IsMemorialDay
  • IsNewYearsDay
  • IsNewYearsEve
  • IsPresidentsDay
  • IsSpecialDate
  • IsThanksgivingDay
  • IsThanksgivingDayAfter
  • IsVeteransDay
  • IsWeekday
  • IsWeekend

To use Business Date Manager

  1. Add a reference helper-dates
  2. Add the namespace directive:
using jwpro.DateHelper.Configuration;
using jwpro.DateHelper.Managers;
  1. The constructor for BusinessDateManager expects an instance of BusinessDateManagerConfiguration to be injected
  2. This can be accomplished by adding at BusinessDateManagerConfiguration section to your appsettings.json file like this:
"BusinessDateManagerConfiguration": {
	"BusinessDayBegin": "08:00",
	"BusinessDayEnd":  "17:00",
	"PaidHolidays": [
		{
			"AssociatedSpecialDate": "Christmas_Day"
		},
		{
			"Name": "Christmas Eve",
			"RelatedSpecialDate": "Christmas_Day",
			"RelatedSpecialDateOffset": -1
		},
		{
			"AssociatedSpecialDate": "Independence_Day"
		},
		{
			"AssociatedSpecialDate": "Labor_Day"
		},
		{
			"AssociatedSpecialDate": "Memorial_Day"
		},
		{
			"Name": "New Years Eve",
			"RelatedSpecialDate": "New_Years_Day",
			"RelatedSpecialDateOffset": 365
		},
		{
			"AssociatedSpecialDate": "New_Years_Day"
		},
		{
			"AssociatedSpecialDate": "Thanksgiving_Day"
		},
		{
			"Name": "Day After Thanksgiving",
			"RelatedSpecialDate": "Thanksgiving_Day",
			"RelatedSpecialDateOffset": 1
		},
		{
			"Name": "Jasons Birthday",
			"DateCalculationString": "(string year) => new DateTime(Int16.Parse(year), 12, 21)"
		}
	]
}
  • The PaidHoliday class expects either
    • An AssociatedSpecialDate that matches a value on the SpecialDate enum or
    • A Name and a RelatedSpecialDate with an appropriate RelatedSpecialDateOffset or
    • A Name and a DateCalculation
      • DateCalculation can be declared in json using DateCalculationString
  1. The values can BusinessDateManagerConfiguration can be configured to be injected in the BusinessDateManager like this:
  _config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .Build();
  _businessConfig = new BusinessDateManagerConfiguration();
  _config.GetSection("BusinessDateManagerConfiguration").Bind(_businessConfig);
  _services.AddSingleton<BusinessDateManagerConfiguration>(_businesConfig);
  1. Use to BusinessDateManager to do the following:
  • Determine if a date is a PaidHoliday:
   var actual = _manager.IsPaidHoliday(inputDate);
  • Get the number of business hours between 2 dates:
    double actual = _manager.GetBusinessHours(beginDate, endDate);
  • Get the date a specific PaidHoliday
    var paidHoliday = _manager.PaidHolidays.FirstOrDefault(x => x.AssociatedSpecialDate == SpecialDate.Thanksgiving_Day);
    DateTime thanksgiving = paidHoliday.GetDate(year: "2020"); 
  • Other Functions:
    • GetPaidHolidayDate

Would love for others to contribute

If you have any questions - drop me a note

Jason Wilson

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.5 232 11/30/2020
0.0.4 201 11/30/2020
0.0.3 194 11/28/2020
0.0.2 330 11/28/2020
0.0.1 184 11/25/2020

Added DateCalculationString to PaidHolidays to allow definition of DateCalculation using a string.  Allows declaration in a json file