first of all i checked this solution:
Find if current time falls in a time range
and tried to compare timespans like that solution
public Boolean CalculateDalUren(DateTime datum, TimeSpan? dalStart, TimeSpan? dalEnd)
{
Boolean isDal = false;
TimeSpan timeBetween = datum.TimeOfDay;
if ((timeBetween >= dalStart))&&(timeBetween < dalEnd)
{
isDal = true;
}
}
return isDal;
}
Note that dalStart is either 21:00 or 23:00 and dalEnd is pretty much always 07:00. And I convert the DateTime to a Timespan.
Now if a Timespan for example is 23:00 then the time is bigger or the same as dalStart but because (and this is an assumption) it is later then dalEnd it will still see the if statement as false. vice versa when its 02:00 hours. Then its not later then dalStart but earlier then dalEnd.
I think this is because my timespan covers 2 days. 21:00 hours from one day, to 07:00 hours the next day. Is there a workaround for this? So i can check if a time is between 21:00 and 07:00 the next morning.