private void DrawBarsForLocation(long originSeconds, Instant originInstant, Instant endInstant, Location location, int y) { LocalDateTime dt1 = originInstant.InZone(location.TimeZone).Date.AtMidnight(); LocalDateTime dt2 = endInstant.InZone(location.TimeZone).LocalDateTime; Debug.Assert(dt1 < dt2); if (dt1.DayOfWeekend(location.Country) == 2) { DrawBar(originSeconds, location, dt1, dt1.PlusDays(1), BarSize.Weekend, "Weekend;W", y); } for (LocalDateTime dt = dt1; dt < dt2; dt = dt.PlusDays(1)) { int dayOfWeekend = dt.DayOfWeekend(location.Country); if (dayOfWeekend == 1) { DrawBar(originSeconds, location, dt, dt.PlusDays(2), BarSize.Weekend, "Weekend;W", y); } if (dayOfWeekend == 1 || dayOfWeekend == 2) { continue; } EarlyClose earlyClose = location.EarlyCloses.Where(x => x.DateTime.Date == dt.Date).SingleOrDefault(EarlyClose.Undefined); if (Holidays.TryGetHoliday(location.Country, location.Region, dt.Date, out Holiday holiday) && !earlyClose.IsValid) { DrawBar(originSeconds, location, dt, dt.PlusDays(1), BarSize.Holiday, "Holiday: " + holiday.Name + ";Holiday;H", y); continue; } foreach (Bar bar in location.Bars) { LocalDateTime start = dt.Date + bar.Start; LocalDateTime end = dt.Date + bar.End; if (earlyClose.IsValid) { if (earlyClose.DateTime.TimeOfDay <= bar.Start) { continue; } if (earlyClose.DateTime.TimeOfDay < bar.End) { end = earlyClose.DateTime; } } string label = bar.Label; if (string.IsNullOrEmpty(label)) { label = location.Name + " TIME"; } if (label.Contains("TIME", StringComparison.Ordinal)) { var timestring = Clock.GetCurrentInstant().InZone(location.TimeZone).ToString("H:mm", null); label = label.Replace("TIME", timestring, StringComparison.Ordinal); } DrawBar(originSeconds, location, start, end, bar.BarSize, label, y); } } }
private async Task Notify(Instant instant) { foreach (Location location in Locations.Where(loc => loc.Notifications.Any())) { LocalDateTime dt = instant.InZone(location.TimeZone).LocalDateTime; // don't notify on weekends if (dt.IsWeekend(location.Country)) { continue; } // don't notify on holidays EarlyClose earlyClose = location.EarlyCloses.Where(x => x.DateTime.Date == dt.Date).SingleOrDefault(EarlyClose.Undefined); if (Holidays.TryGetHoliday(location.Country, location.Region, dt.Date, out Holiday holiday) && !earlyClose.IsValid) { continue; } if (earlyClose.IsValid && dt.TimeOfDay > earlyClose.DateTime.TimeOfDay) { continue; } // holiday earlyClose Notify // Y N No // Y Y <= earlyClose // N Y <= earlyClose // N N Yes foreach (Notification notification in location.Notifications) { if (dt.TimeOfDay == notification.Time) { await Speech.AnnounceTime(dt, location.Name, notification.Text).ConfigureAwait(false); } } } }