SetDayOfWeek() public method

public SetDayOfWeek ( DayOfWeek day, bool active ) : void
day DayOfWeek
active bool
return void
コード例 #1
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());
        }
コード例 #2
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();
		}