예제 #1
0
        // "opening_times": {
        //
        //     "regular_hours": [
        //       {
        //         "weekday": 1,
        //         "period_begin": "08:00",
        //         "period_end":   "20:00"
        //       },
        //       {
        //         "weekday": 2,
        //         "period_begin": "08:00",
        //         "period_end":   "20:00"
        //       },
        //       {
        //         "weekday": 3,
        //         "period_begin": "08:00",
        //         "period_end":   "20:00"
        //       },
        //       {
        //         "weekday": 4,
        //         "period_begin": "08:00",
        //         "period_end":   "20:00"
        //       },
        //       {
        //         "weekday": 5,
        //         "period_begin": "08:00",
        //         "period_end":   "20:00"
        //       }
        //     ],
        //
        //     "twentyfourseven": false,
        //
        //     "exceptional_openings": [
        //       {
        //         "period_begin": "2014-06-21T09:00:00Z",
        //         "period_end":   "2014-06-21T12:00:00Z"
        //       }
        //     ],
        //
        //     "exceptional_closings": [
        //       {
        //         "period_begin": "2014-06-24T00:00:00Z",
        //         "period_end":   "2014-06-25T00:00:00Z"
        //       }
        //     ]
        //
        //   }


        public OpeningTimes SetRegularOpening(DayOfWeek Weekday,
                                              HourMin Begin,
                                              HourMin End)
        {
            _RegularOpenings[(int)Weekday] = new RegularHours(Weekday, Begin, End);

            return(this);
        }
예제 #2
0
        public OpeningTimes(DayOfWeek FromWeekday,
                            DayOfWeek ToWeekday,
                            HourMin Begin,
                            HourMin End,
                            String FreeText = "")

            : this(false, FreeText)

        {
            SetRegularOpening(FromWeekday, ToWeekday, Begin, End);
        }
예제 #3
0
        /// <summary>
        /// Create a new regular hours object.
        /// </summary>
        /// <param name="DayOfWeek">Day of the week.</param>
        /// <param name="PeriodBegin">Begin of the regular period.</param>
        /// <param name="PeriodEnd">End of the regular period.</param>
        public RegularHours(DayOfWeek DayOfWeek,
                            HourMin PeriodBegin,
                            HourMin PeriodEnd)
        {
            #region Initial checks

            if (PeriodEnd.Hour < PeriodBegin.Hour ||

                (PeriodEnd.Hour == PeriodBegin.Hour &&
                 PeriodEnd.Minute < PeriodBegin.Minute))
            {
                throw new ArgumentException("The end period must be after the start period!", nameof(PeriodEnd));
            }

            #endregion

            this.DayOfWeek   = DayOfWeek;
            this.PeriodBegin = PeriodBegin;
            this.PeriodEnd   = PeriodEnd;
        }
예제 #4
0
        public OpeningTimes SetRegularOpening(DayOfWeek FromWeekday,
                                              DayOfWeek ToWeekday,
                                              HourMin Begin,
                                              HourMin End)
        {
            var _FromWeekday = (int)FromWeekday;
            var _ToWeekday   = (int)ToWeekday;

            if (_ToWeekday < _FromWeekday)
            {
                _ToWeekday += 7;
            }

            for (var weekday = _FromWeekday; weekday <= _ToWeekday; weekday++)
            {
                _RegularOpenings[weekday % 7] = new RegularHours((DayOfWeek)(weekday % 7), Begin, End);
            }

            return(this);
        }
예제 #5
0
        public static Boolean TryParse(String Text, out OpeningTimes OpeningTimes)
        {
            if (Text == _24_7)
            {
                OpeningTimes = new OpeningTimes(true);
                return(true);
            }

            OpeningTimes = null;

            if (Text == "{}")
            {
                return(true);
            }

            var match = Regex.Match(Text, "([a-zA-Z]+) - ([a-zA-Z]+) (([0-9]{2}:[0-9]{2})h - ([0-9]{2}:[0-9]{2})h|open|closed)");

            if (!match.Success)
            {
                return(false);
            }

            #region Parse weekdays

            DayOfWeek FromWeekday;

            switch (match.Groups[1].Value.ToLower())
            {
            case "mo":
            case "mon":
            case "monday":
                FromWeekday = DayOfWeek.Monday;
                break;

            case "tu":
            case "di":
            case "tue":
            case "tuesday":
                FromWeekday = DayOfWeek.Tuesday;
                break;

            case "we":
            case "mi":
            case "wed":
            case "wednesday":
                FromWeekday = DayOfWeek.Wednesday;
                break;

            case "th":
            case "do":
            case "thu":
            case "thursday":
                FromWeekday = DayOfWeek.Thursday;
                break;

            case "fr":
            case "fri":
            case "friday":
                FromWeekday = DayOfWeek.Friday;
                break;

            case "sa":
            case "sat":
            case "saturday":
                FromWeekday = DayOfWeek.Saturday;
                break;

            case "su":
            case "so":
            case "sun":
            case "sunday":
                FromWeekday = DayOfWeek.Sunday;
                break;

            default:
                return(false);
            }

            DayOfWeek ToWeekday;

            switch (match.Groups[2].Value.ToLower())
            {
            case "mo":
            case "mon":
            case "monday":
                ToWeekday = DayOfWeek.Monday;
                break;

            case "tu":
            case "di":
            case "tue":
            case "tuesday":
                ToWeekday = DayOfWeek.Tuesday;
                break;

            case "we":
            case "mi":
            case "wed":
            case "wednesday":
                ToWeekday = DayOfWeek.Wednesday;
                break;

            case "th":
            case "do":
            case "thu":
            case "thursday":
                ToWeekday = DayOfWeek.Thursday;
                break;

            case "fr":
            case "fri":
            case "friday":
                ToWeekday = DayOfWeek.Friday;
                break;

            case "sa":
            case "sat":
            case "saturday":
                ToWeekday = DayOfWeek.Saturday;
                break;

            case "su":
            case "so":
            case "sun":
            case "sunday":
                ToWeekday = DayOfWeek.Sunday;
                break;

            default:
                return(false);
            }

            #endregion

            #region Parse hours...

            HourMin Begin;
            HourMin End;

            if (HourMin.TryParse(match.Groups[4].Value, out Begin) &&
                HourMin.TryParse(match.Groups[5].Value, out End))
            {
                OpeningTimes = new OpeningTimes(FromWeekday, ToWeekday, Begin, End);
                return(true);
            }

            #endregion

            #region ...or parse "open"

            else if (match.Groups[3].Value == "open")
            {
                OpeningTimes = new OpeningTimes(FromWeekday, ToWeekday);
                return(true);
            }

            #endregion

            #region ...or parse "closed"

            else if (match.Groups[3].Value == "closed")
            {
                OpeningTimes = new OpeningTimes(false, Text);
                return(true);
            }

            #endregion

            return(false);
        }