/// <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 static bool IsOpen24Hours(this OpeningHoursWeekdayItem model) { throw new NotImplementedException(); //if (model == null) return false; //if (!model.IsOpen) return false; //var midnight = new TimeSpan(0,0,0); //return model.Opens == midnight && model.Closes == midnight; }
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>(); }
///// <summary> ///// Initializes a new instance with the specified <code>weekdays</code> and <code>holidays</code>. ///// </summary> ///// <param name="weekdays">The weekdays that should make up the instance.</param> ///// <param name="holidays">The holidays that should make up the model.</param> //public OpeningHoursModel(Dictionary<DayOfWeek, OpeningHoursWeekdayItem> weekdays, OpeningHoursHolidayItem[] holidays) : base(null) { // Weekdays = weekdays ?? new Dictionary<DayOfWeek, OpeningHoursWeekdayItem>(); // Holidays = holidays ?? new OpeningHoursHolidayItem[0]; // _holidays = Holidays.Where(x => x.Date != null).ToDictionary(x => x.Date.ToString("yyyyMMdd")); //} /// <summary> /// Initializes a new instance from the specified <see cref="JObject"/>. /// </summary> /// <param name="obj">The instance of <see cref="JObject"/> representing the model.</param> private OpeningHoursModel(JObject obj) : base(obj) { // Parse the weekdays Weekdays = new Dictionary <DayOfWeek, OpeningHoursWeekdayItem>(); for (int i = 0; i < 7; i++) { DayOfWeek dayOfWeek = (DayOfWeek)i; Weekdays.Add(dayOfWeek, obj.GetObject("weekdays." + i, x => OpeningHoursWeekdayItem.Parse(x, dayOfWeek))); } // Parse holidays Holidays = obj.GetArrayItems("holidays", OpeningHoursHolidayItem.Parse); // Create a dictionary with the holidays - for O(1) lookups _holidays = Holidays.Where(x => x.IsValid).DistinctBy(x => x.Date.ToString("yyyyMMdd")).ToDictionary(x => x.Date.ToString("yyyyMMdd")); }
/// <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); }