joaomatossilva / DateTimeExtensions

This project is a merge of several common DateTime operations on the form of extensions to System.DateTime, including natural date difference text (precise and human rounded), holidays and working days calculations on several culture locales.
http://datetimeextensions.azurewebsites.net/
Other
775 stars 348 forks source link

Add Business Hours Check Extension Method #184

Open AhmedFaizanDev opened 3 months ago

AhmedFaizanDev commented 3 months ago

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.");
}
rabbitbrother91 commented 2 months ago

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. ^-^

AhmedFaizanDev commented 2 months ago

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!