I'm setting up a scheduling system for one of my projects and one thing in particular that I need to do is allow for multiple windows to be present within each day. A window would represent two points in time, the start and the end.
I am not sure just how I should approach this issue. I can do this in a very hacky way but I would rather know how to do it right, so that I can be satisfied that my code is as it should be.
What I'm currently attempting to do is as seen here:
public class ScheduleWindow
{
public string Name;
public DateTime EndTime;
public DateTime StartTime;
}
I have a name id for my schedule, but for this that is irrelevant. I have a date in time at which the window will start. I have a date in time at which the window will end.
The intent for the following method is to add a window to a schedule. I want the schedule to represent my day, so I'm using the current year, month and day and then setting the hours and minutes to the points in time that I would like this window to be active.
public void AddWindow(string name, int startHour, int endHour, int startMinute, int endMinute)
{
var year = DateTime.Now.Year;
var month = DateTime.Now.Month;
var day = DateTime.Now.Day;
var startTime = new DateTime(year: year, month: month, day: day, hour: startHour, minute: startMinute, second: 0, millisecond: 0);
var endTime = new DateTime(year: year, month: month, day: day, hour: endHour, minute: endMinute, second: 0, millisecond: 0);
var window = new ScheduleWindow()
{
EndTime = endTime,
StartTime = startTime,
Name = name
};
_scheduleWindows.Add(window);
}
So now we're to the root of my issue. I am actually completely unsure of how to check if we are within that time window.
`public bool WindowIsActive()
{
foreach (var window in _scheduleWindows)
{
...
//if any window is currently active, return true
}
}`
I've been fiddling here with this code for some time now, and any help would be super appreciated. If anyone can give me some pointers to perhaps a solution that would work better, that would be awesome!
The goal is to check and see if any window is currently active. Currently, I have no clue how.