/// <summary>
        /// Gets an instance of <see cref="OpeningHoursDayOffset"/> representing the day at the specified
        /// <paramref name="date"/>. If <strong>Require Holiday Dates</strong> has been checked in the pre-value
        /// editor, holidays will be taken into account as well.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns>An instance of <see cref="OpeningHoursDayOffset"/> representing the day at the specified
        /// <paramref name="date"/>.</returns>
        public OpeningHoursDayOffset GetDay(DateTimeOffset date)
        {
            // Get information about the weekday (and whether it is a holiday)
            OpeningHoursWeekdayItem woh = Weekdays[date.DayOfWeek];
            OpeningHoursHolidayItem hoh = GetHoliday(date);

            // Initialize the instance for the day
            return(new OpeningHoursDayOffset(date, woh, hoh));
        }
 public OpeningHoursDay(DateTime date, OpeningHoursWeekdayItem weekday, OpeningHoursHolidayItem holiday)
 {
     Date    = date;
     Weekday = weekday;
     Holiday = holiday;
     IsOpen  = holiday == null ? weekday.IsOpen : holiday.IsOpen;
     Label   = holiday == null ? weekday.Label : holiday.Label;
     Items   = (holiday == null ? weekday.Items : holiday.Items).Select(x => new OpeningHoursDayTimeSlot(date, x)).ToArray();
 }
 /// <summary>
 /// Initializes a new instance with default options.
 /// </summary>
 public OpeningHoursModel() : base(null)
 {
     Weekdays = new Dictionary <DayOfWeek, OpeningHoursWeekdayItem>();
     for (int i = 0; i < 7; i++)
     {
         Weekdays.Add((DayOfWeek)i, OpeningHoursWeekdayItem.GetEmptyModel((DayOfWeek)i));
     }
     Holidays  = new OpeningHoursHolidayItem[0];
     _holidays = new Dictionary <string, OpeningHoursHolidayItem>();
 }
        public static OpeningHoursWeekdayItem TodaysOpeningHours(this OpeningHoursModel model, DateTime today)
        {
            if (model == null)
            {
                return(null);
            }

            // Find any holidays with todays date
            if (model.Holidays != null)
            {
                OpeningHoursHolidayItem holiday = model.Holidays.FirstOrDefault(x => x.Date.Date == today.Date);
                if (holiday != null)
                {
                    return(holiday);
                }
            }

            // No holidays, so check general weekday opening hours
            return(model.Weekdays != null && model.Weekdays.ContainsKey(today.DayOfWeek) ? model.Weekdays[today.DayOfWeek] : null);
        }
        /// <summary>
        /// Gets an array of the next <paramref name="count"/> upcoming days. If <strong>Require Holiday Dates</strong>
        /// has been checked in the pre-value editor, holidays will be incorporated into the result.
        /// </summary>
        /// <param name="count">The amount of days to be returned (including the current day).</param>
        /// <param name="timeZone">The <see cref="TimeZoneInfo"/> that should be used.</param>
        /// <returns>An array of <see cref="OpeningHoursDay"/> representing the opening hours of the upcoming days.</returns>
        public OpeningHoursDayOffset[] GetUpcomingDays(int count, TimeZoneInfo timeZone)
        {
            // Array containing the days
            OpeningHoursDayOffset[] upcomingDays = new OpeningHoursDayOffset[count];

            // Iterate through the days one by one
            for (int i = 0; i < 14; i++)
            {
                // Get the current timestamp (according to the specified time zone)
                DateTimeOffset timeZoneNow = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, timeZone);

                // Get the timestamp for the day
                DateTimeOffset dt = timeZoneNow.AddDays(i);

                OpeningHoursWeekdayItem weekday = Weekdays[dt.DayOfWeek];
                OpeningHoursHolidayItem holiday = GetHoliday(dt);

                upcomingDays[i] = new OpeningHoursDayOffset(dt, weekday, holiday);
            }

            // Return the array
            return(upcomingDays);
        }
Example #6
0
 /// <summary>
 /// Gets a reference to the holiday at the specified <paramref name="date"/>, or <code>null</code> if the day
 /// doesn't represent a holiday.
 /// </summary>
 /// <param name="date">The date.</param>
 /// <param name="holiday">A reference to the holiday.</param>
 /// <returns><code>true</code> if the day represents a holiday, otherwise <code>false</code>.</returns>
 public bool TryGetHoliday(DateTimeOffset date, out OpeningHoursHolidayItem holiday)
 {
     return(Model.TryGetHoliday(date, out holiday));
 }
 /// <summary>
 /// Gets a reference to the holiday at the specified <paramref name="date"/>, or <code>null</code> if the day
 /// doesn't represent a holiday.
 /// </summary>
 /// <param name="date">The date.</param>
 /// <param name="holiday">A reference to the holiday.</param>
 /// <returns><code>true</code> if the day represents a holiday, otherwise <code>false</code>.</returns>
 public bool TryGetHoliday(DateTimeOffset date, out OpeningHoursHolidayItem holiday)
 {
     return(_holidays.TryGetValue(date.ToString("yyyyMMdd"), out holiday));
 }