Example #1
0
        public DayOfWeekTimeRange Clone()
        {
            DayOfWeekTimeRange range = new DayOfWeekTimeRange();

            range.Active    = Active;
            range.Sunday    = Sunday;
            range.Monday    = Monday;
            range.Tuesday   = Tuesday;
            range.Wednesday = Wednesday;
            range.Thursday  = Thursday;
            range.Friday    = Friday;
            range.Saturday  = Saturday;
            range.StartTime = StartTime;
            range.EndTime   = EndTime;
            return(range);
        }
Example #2
0
 public void AddTimeRange(string daysOfWeek, string timeRanges, bool active)
 {
     _ranges.AddRange(DayOfWeekTimeRange.Parse(daysOfWeek, timeRanges, active));
 }
Example #3
0
 public void AddTimeRange(DayOfWeekTimeRange range)
 {
     _ranges.Add(range);
 }
Example #4
0
        public static DayOfWeekTimeRange[] Parse(string daysOfWeek, string timeRanges, bool active)
        {
            List <DayOfWeekTimeRange> list = new List <DayOfWeekTimeRange>();

            DayOfWeekTimeRange template = new DayOfWeekTimeRange();

            template.Active = active;

            if (!String.IsNullOrEmpty(daysOfWeek))
            {
                string[] days = daysOfWeek.ToLower().Split(',');
                foreach (string day in days)
                {
                    if (day == "-")
                    {
                        template.SetDaysOfWeek(DayOfWeek.Sunday, DayOfWeek.Saturday, true);
                        break;
                    }

                    string[] range = day.Split('-');
                    if (range.Length == 1)
                    {
                        DayOfWeek d = ParseDayOfWeek(range[0]);
                        template.SetDayOfWeek(d, true);
                    }
                    else if (range.Length == 2)
                    {
                        DayOfWeek d1 = ParseDayOfWeek(range[0]);
                        DayOfWeek d2 = ParseDayOfWeek(range[1]);
                        for (; d1 <= d2; d1++)
                        {
                            template.SetDayOfWeek(d1, true);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Invalid day range", "daysOfWeek");
                    }
                }
            }
            else
            {
                template.SetDaysOfWeek(DayOfWeek.Sunday, DayOfWeek.Saturday, true);
            }

            if (!String.IsNullOrEmpty(timeRanges))
            {
                string[] times = timeRanges.Split(',');
                foreach (string time in times)
                {
                    DayOfWeekTimeRange clone = template.Clone();
                    string[]           range = time.Split('-');
                    if (range.Length == 2)
                    {
                        if (String.IsNullOrEmpty(range[0]))
                        {
                            clone.StartTime = StartOfDay;
                        }
                        else
                        {
                            clone.StartTime = ParseTime(range[0]);
                        }

                        if (String.IsNullOrEmpty(range[1]))
                        {
                            clone.EndTime = EndOfDay;
                        }
                        else
                        {
                            clone.EndTime = ParseTime(range[1]);
                        }

                        list.Add(clone);
                    }
                    else
                    {
                        throw new ArgumentException("Invalid time range", "timeRanges");
                    }
                }
            }
            else
            {
                list.Add(template);
            }

            return(list.ToArray());
        }
Example #5
0
		public void AddTimeRange(DayOfWeekTimeRange range) {
			_ranges.Add(range);
		}
Example #6
0
		public static DayOfWeekTimeRange[] Parse(string daysOfWeek, string timeRanges, bool active) {
			List<DayOfWeekTimeRange> list = new List<DayOfWeekTimeRange>();

			DayOfWeekTimeRange template = new DayOfWeekTimeRange();
			template.Active = active;

			if (!String.IsNullOrEmpty(daysOfWeek)) {
				string[] days = daysOfWeek.ToLower().Split(',');
				foreach (string day in days) {
					if (day == "-") {
						template.SetDaysOfWeek(DayOfWeek.Sunday, DayOfWeek.Saturday, true);
						break;
					}

					string[] range = day.Split('-');
					if (range.Length == 1) {
						DayOfWeek d = ParseDayOfWeek(range[0]);
						template.SetDayOfWeek(d, true);
					} else if (range.Length == 2) {
						DayOfWeek d1 = ParseDayOfWeek(range[0]);
						DayOfWeek d2 = ParseDayOfWeek(range[1]);
						for (; d1 <= d2; d1++) {
							template.SetDayOfWeek(d1, true);
						}
					} else {
						throw new ArgumentException("Invalid day range", "daysOfWeek");
					}
				}
			} else {
				template.SetDaysOfWeek(DayOfWeek.Sunday, DayOfWeek.Saturday, true);
			}

			if (!String.IsNullOrEmpty(timeRanges)) {
				string[] times = timeRanges.Split(',');
				foreach (string time in times) {
					DayOfWeekTimeRange clone = template.Clone();
					string[] range = time.Split('-');
					if (range.Length == 2) {
						if (String.IsNullOrEmpty(range[0]))
							clone.StartTime = StartOfDay;
						else
							clone.StartTime = ParseTime(range[0]);

						if (String.IsNullOrEmpty(range[1]))
							clone.EndTime = EndOfDay;
						else
							clone.EndTime = ParseTime(range[1]);

						list.Add(clone);
					} else {
						throw new ArgumentException("Invalid time range", "timeRanges");
					}
				}
			} else {
				list.Add(template);
			}

			return list.ToArray();
		}
Example #7
0
		public DayOfWeekTimeRange Clone() {
			DayOfWeekTimeRange range = new DayOfWeekTimeRange();
			range.Active = Active;
			range.Sunday = Sunday;
			range.Monday = Monday;
			range.Tuesday = Tuesday;
			range.Wednesday = Wednesday;
			range.Thursday = Thursday;
			range.Friday = Friday;
			range.Saturday = Saturday;
			range.StartTime = StartTime;
			range.EndTime = EndTime;
			return range;
		}