Open bjarnef opened 7 years ago
I found that I needed this functionality too. I did want it to take today into account. My version is a little longer because of that and some differences with the text that my version prints (today, tomorrow, or day of week). Anyway, here's the snippet incase it helps anyone.
foreach(OpeningHoursDay day in openingHours.GetUpcomingDays(7))
{
string dayText = "";
string timeText = "";
if(day.IsOpen){
dayText = day.WeekDayName;
if(day.IsToday){ dayText = "today"; }
else if(day.IsTomorrow){ dayText = "tomorrow"; }
foreach(OpeningHoursDayTimeSlot item in day.Items)
{
if(item.Opens < DateTime.Now){ continue; }
// Dump minutes if they equal "00", update format of am/pm to be lowercase include periods (AP style).
timeText = item.Opens.ToString("h:mm tt").ToLower().Replace(":00", "").Replace("m", ".m.");
}
}
// If timeText is empty we'll just go to the next day. Otherwise print the result and break out of the foreach.
if(timeText != ""){
<p class="estimated">Re-opening @dayText at @timeText</p>
break;
}
}
I would be useful to have an method to get next opening hours, e.g.
GetNextOpeningHours()
Maybe with the option to choose whether it should take today into account - maybe with the change of https://github.com/bomortensen/Our.Umbraco.OpeningHours/issues/15For now I do like this: