DateTimeExtensions icon indicating copy to clipboard operation
DateTimeExtensions copied to clipboard

Add Business Hours Check Extension Method

Open AhmedFaizanDev opened this issue 1 year ago • 7 comments

Description: We could implement a new extension method IsWithinBusinessHours for the DateTime class. This will help check if a specific DateTime falls within a given range of business hours. The method should take startTime and endTime as TimeSpan parameters and return true if the DateTime is between them.

Example Method Signature:

bool IsWithinBusinessHours(this DateTime dateTime, TimeSpan startTime, TimeSpan endTime)

This feature would be handy for checking if a time is during standard working hours. It could be used in scheduling systems or for customer support hours.

Example Usage:

DateTime now = DateTime.Now;
bool isWithinBusinessHours = now.IsWithinBusinessHours(new TimeSpan(9, 0, 0), new TimeSpan(17, 0, 0));

if (isWithinBusinessHours)
{
    Console.WriteLine("The current time is within business hours.");
}
else
{
    Console.WriteLine("The current time is outside business hours.");
}

AhmedFaizanDev avatar Jul 30 '24 12:07 AhmedFaizanDev

Hi, The proposed extension method IsWithinBusinessHours for the DateTime class checks if a specific DateTime falls within a defined range of business hours. Here's a concise overview:

Method Signature:

bool IsWithinBusinessHours(this DateTime dateTime, TimeSpan startTime, TimeSpan endTime)

Purpose:

This method helps determine if a given time is during standard working hours, useful for scheduling or customer support systems.

Example Usage:

DateTime now = DateTime.Now;
bool isWithinBusinessHours = now.IsWithinBusinessHours(new TimeSpan(9, 0, 0), new TimeSpan(17, 0, 0));

if (isWithinBusinessHours)
{
    Console.WriteLine("The current time is within business hours.");
}
else
{
    Console.WriteLine("The current time is outside business hours.");
}

Hope help. ^-^

BugsBunnyDr avatar Aug 07 '24 13:08 BugsBunnyDr

Hi, The proposed extension method IsWithinBusinessHours for the DateTime class checks if a specific DateTime falls within a defined range of business hours. Here's a concise overview:

Method Signature:

bool IsWithinBusinessHours(this DateTime dateTime, TimeSpan startTime, TimeSpan endTime)

Purpose:

This method helps determine if a given time is during standard working hours, useful for scheduling or customer support systems.

Example Usage:

DateTime now = DateTime.Now;
bool isWithinBusinessHours = now.IsWithinBusinessHours(new TimeSpan(9, 0, 0), new TimeSpan(17, 0, 0));

if (isWithinBusinessHours)
{
    Console.WriteLine("The current time is within business hours.");
}
else
{
    Console.WriteLine("The current time is outside business hours.");
}

Hope help. ^-^

Hey! Thanks for the summary and If there's anything more to clarify, I'm happy to help. Otherwise, I'd be more than willing to contribute by implementing this feature and submitting a pull request if you’d like.

Looking forward to your thoughts!

AhmedFaizanDev avatar Aug 07 '24 14:08 AhmedFaizanDev

How would you handle if the business is closed on Saturdays and Sundays? The proposed extension only looks at the time.

Dan-613 avatar Nov 08 '24 18:11 Dan-613

Is this issue resolved. Anyone?

github-roushan avatar Nov 18 '24 14:11 github-roushan

Is this issue resolved. Anyone?

I still don't even know what the problem is. Maybe with a Unit test showing the expected result could help clear things up

joaomatossilva avatar Nov 21 '24 20:11 joaomatossilva

I am sure this can be closed... there is test coverage for the extension in BusinessHoursTests.cs

josiahwelch avatar Nov 23 '24 05:11 josiahwelch

Ok I am taking a look into it and will close it

github-roushan avatar Nov 23 '24 12:11 github-roushan