Last active
April 17, 2018 10:09
-
-
Save alexohneander/0c4a0fd909ff051f3eaf0ff13dca06cb to your computer and use it in GitHub Desktop.
Is the current day a weekday or a day of 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
public Boolean weekend() | |
{ | |
DateTime date = DateTime.Now; | |
if ((date.DayOfWeek == DayOfWeek.Saturday) || (date.DayOfWeek == DayOfWeek.Sunday)) | |
{ | |
Console.WriteLine("This is a weekend"); | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
public Boolean EndofWorkingDay() | |
{ | |
TimeSpan start = TimeSpan.Parse("08:00"); // 10 PM | |
TimeSpan end = TimeSpan.Parse("18:00"); // 2 AM | |
TimeSpan now = DateTime.Now.TimeOfDay; | |
if (start <= end) | |
{ | |
// start and stop times are in the same day | |
if (now >= start && now <= end) | |
{ | |
// current time is between start and stop | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
else | |
{ | |
// start and stop times are in different days | |
if (now >= start || now <= end) | |
{ | |
// current time is between start and stop | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment