I have a problem auto-detecting the start date and end date to store the day of the week, start time, and end time in DayBlock
objects. Why do I need to auto-detect? Because startDate
and endDate
are selected by users. In the future, they cannot be hardcoded. I just know the hard-coded way like below:
//startDate = 22 Nov 2022 05:00 PM
//endDate = 25 Nov 2022 12:00 PM
class DayBlock
{
public DayOfWeek DayOfWeek { get; set; }
public TimeSpan Start { get; set; }
public TimeSpan End { get; set; }
}
DayBlock[] blockWeekdays = {
new DayBlock {DayOfWeek=DayOfWeek.Tuesday, Start=TimeSpan.FromHours(17), End=TimeSpan.FromHours(24)},
new DayBlock {DayOfWeek=DayOfWeek.Wednesday, Start=TimeSpan.FromHours(0), End=TimeSpan.FromHours(24)},
new DayBlock {DayOfWeek=DayOfWeek.Thursday, Start=TimeSpan.FromHours(0), End=TimeSpan.FromHours(24)},
new DayBlock {DayOfWeek=DayOfWeek.Friday, Start=TimeSpan.FromHours(0), End=TimeSpan.FromHours(12)},
};
And how to include the hours and minutes in the DayBlock
's timespans, because currently just can add hours in the time span, if the start time or end time includes minutes, how can I add them in the DayBlock?
I tried below the code but it doesn't work:
//startDate = 22 Nov 2022 05:30 PM
//endDate = 25 Nov 2022 1:15 PM
class DayBlock
{
public DayOfWeek DayOfWeek { get; set; }
public TimeSpan Start { get; set; }
public TimeSpan End { get; set; }
}
DayBlock[] blockWeekdays = {
new DayBlock {DayOfWeek=DayOfWeek.Tuesday, Start=TimeSpan.FromHours(17:30), End=TimeSpan.FromHours(24)},
new DayBlock {DayOfWeek=DayOfWeek.Wednesday, Start=TimeSpan.FromHours(0), End=TimeSpan.FromHours(24)},
new DayBlock {DayOfWeek=DayOfWeek.Thursday, Start=TimeSpan.FromHours(0), End=TimeSpan.FromHours(24)},
new DayBlock {DayOfWeek=DayOfWeek.Friday, Start=TimeSpan.FromHours(0), End=TimeSpan.FromHours(13:15)},
};
I hope someone can help me solve the problem.