private static void WorkOutNextOpen(LocationViewModel model, OpeningTimes opening, DateTime ukNow) { if (opening.Scheduled && opening.OpensAtTime.HasValue && opening.OpensAtTime > ukNow && opening.OpensAtTime < model.NextOpen) { model.NextOpen = opening.OpensAtTime.Value; } if (opening.Scheduled && opening.OpensAgainAtTime.HasValue && opening.OpensAgainAtTime > ukNow && opening.OpensAgainAtTime < model.NextOpen) { model.NextOpen = opening.OpensAgainAtTime.Value; } // If it's open this day, and we've no better offer, it'll be open again this time next week if (opening.Scheduled && opening.OpensAtTime.HasValue) { var sameTimeNextWeek = opening.OpensAtTime.Value.AddDays(7); if (model.NextOpen > sameTimeNextWeek) { model.NextOpen = sameTimeNextWeek; } } }
private static void WorkOutOpenUntil(LocationViewModel model, DateTime ukNow, OpeningTimes opening) { var today = (ukNow.DayOfWeek.ToString().Substring(0, 2).ToUpperInvariant() == opening.Day.Substring(0, 2).ToUpperInvariant()); var now = ukNow.TimeOfDay; var open1 = (opening.OpensAtTime.HasValue && opening.ClosesAtTime.HasValue && now >= opening.OpensAtTime.Value.TimeOfDay && now <= opening.ClosesAtTime.Value.TimeOfDay); var open2 = (opening.OpensAgainAtTime.HasValue && opening.ClosesAgainAtTime.HasValue && now >= opening.OpensAgainAtTime.Value.TimeOfDay && now <= opening.ClosesAgainAtTime.Value.TimeOfDay); var open = today && opening.Scheduled && (open1 || open2); if (open && open1) { model.OpenUntil = opening.ClosesAtTime; } if (open && open2) { model.OpenUntil = opening.ClosesAgainAtTime; } }