Created
December 3, 2019 15:03
-
-
Save JaimeStill/8c072357049444439d52b309873cebbe to your computer and use it in GitHub Desktop.
In C#, project a date in the future and ensure it does not fall on the weekend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class DateExtensions | |
{ | |
static DateTime PreventWeekend(this DateTime dateTime) | |
{ | |
switch (dateTime.DayOfWeek) | |
{ | |
case DayOfWeek.Saturday: | |
return dateTime.AddDays(2); | |
case DayOfWeek.Sunday: | |
return dateTime.AddDays(1); | |
default: | |
return dateTime; | |
} | |
} | |
// Example Usage | |
static DateTime Calculate24Hour(this Datetime dateTime) => dateTime.AddHours(20).PreventWeekend(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment