Exemple #1
0
        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
                Holiday?   holiday    = Holidays.TryGetHoliday(location.Country, location.Region, dt.Date);
                EarlyClose?earlyClose = location.EarlyCloses.Where(x => x.DateTime.Date == dt.Date).SingleOrDefault();

                if (holiday is not null && earlyClose is null)
                {
                    continue;
                }
                if (earlyClose is not null && 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);
                    }
                }
            }
        }