The Weekend class provides a mechanism to test if a Date falls on a weekend (e.g. non-working day). In traditionally Christian countries Saturday and Sunday are non-working but other religions have selected other days.
Esempio n. 1
0
        /// <summary>
        /// Parses the XML data file indicated by the URI to extract default sets
        /// of calendars.
        /// </summary>
        /// <param name="uri">The URI of the source XML document.</param>
        private static void ParseCalendars(string uri)
        {
            RuleBasedCalendar calendar = null;
            XmlReader         reader   = XmlReader.Create(uri);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    if (reader.LocalName.Equals("calendar"))
                    {
                        string  name    = reader ["name"];
                        Weekend weekend = Weekend.ForName(reader ["weekend"]);

                        if ((name != null) && (weekend != null))
                        {
                            calendar = new RuleBasedCalendar(name, weekend);
                        }
                        else
                        {
                            calendar = null;
                        }
                    }
                    else if (reader.LocalName.Equals("fixed"))
                    {
                        string   name     = reader ["name"];
                        int      from     = Int32.Parse(reader ["from"]);
                        int      until    = Int32.Parse(reader ["until"]);
                        int      month    = ConvertMonth(reader ["month"]);
                        int      date     = Int32.Parse(reader ["date"]);
                        DateRoll dateRoll = DateRoll.ForName(reader ["roll"]);

                        if ((calendar != null) && (month != 0) && (dateRoll != null))
                        {
                            calendar.AddRule(new CalendarRule.Fixed(name, from, until, month, date, dateRoll));
                        }
                    }
                    else if (reader.LocalName.Equals("offset"))
                    {
                        string name    = reader ["name"];
                        int    from    = Int32.Parse(reader ["from"]);
                        int    until   = Int32.Parse(reader ["until"]);
                        int    when    = ConvertWhen(reader ["when"]);
                        int    weekday = ConvertWeekday(reader ["weekday"]);
                        int    month   = ConvertMonth(reader ["month"]);

                        if ((calendar != null) && (month != 0) && (when != 0) && (weekday != 0))
                        {
                            calendar.AddRule(new CalendarRule.Offset(name, from, until, when, weekday, month));
                        }
                    }
                    else if (reader.LocalName.Equals("easter"))
                    {
                        string name   = reader ["name"];
                        int    from   = Int32.Parse(reader ["from"]);
                        int    until  = Int32.Parse(reader ["until"]);
                        int    offset = Int32.Parse(reader ["offset"]);

                        if (calendar != null)
                        {
                            calendar.AddRule(new CalendarRule.Easter(name, from, until, offset));
                        }
                    }
                    break;
                }
                }
            }
            reader.Close();
        }
 /// <summary>
 /// Constructs a <b>RuleBasedCalendar</b> with the given name and
 /// <see cref="Weekend"/> rule.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="weekend"></param>
 public RuleBasedCalendar(string name, Weekend weekend)
     : base(name)
 {
     this.weekend = weekend;
 }
 /// <summary>
 /// Constructs a <b>RuleBasedCalendar</b> with the given name and
 /// <see cref="Weekend"/> rule.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="weekend"></param>
 public RuleBasedCalendar(string name, Weekend weekend)
     : base(name)
 {
     this.weekend = weekend;
 }