Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to get next openings hours set #21

Open
bjarnef opened this issue Dec 8, 2016 · 1 comment
Open

Add method to get next openings hours set #21

bjarnef opened this issue Dec 8, 2016 · 1 comment

Comments

@bjarnef
Copy link
Contributor

bjarnef commented Dec 8, 2016

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 #15

For now I do like this:

var nextDays = openingHours.GetUpcomingDays(7);
var nextDayOpen = nextDays.Where(x => x.IsOpen && !x.IsToday).FirstOrDefault();
<p>We are opening again on @nextDayOpen.WeekDayName at @nextDayOpen.Items[0].Opens.ToString(@"HH\:mm")</p>
@fret1224
Copy link

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;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants