Instances of the DateRoll class carry out financial date adjustments. A DateRoll instance will apply a particular adjustment rule to a given Date using a business day Calendar to skip non-working days.
 /// <summary>
 /// Constructs a <b>Fixed</b> date calender rule.
 /// </summary>
 /// <param name="name">The name of the holiday.</param>
 /// <param name="from">The first year in which the holiday occurs.</param>
 /// <param name="until">The last year in which the holiday occurs.</param>
 /// <param name="month">The month of the year where the holidays falls.</param>
 /// <param name="dayOfMonth">The day of the month where the holiday falls.</param>
 /// <param name="dateRoll">The <see cref="DateRoll"/> used to adjust dates.</param>
 public Fixed(string name, int from, int until, int month, int dayOfMonth, DateRoll dateRoll)
     : base(name, from, until)
 {
     this.month		= month;
     this.dayOfMonth	= dayOfMonth;
     this.dateRoll	= dateRoll;
 }
 /// <summary>
 /// Constructs a <b>Fixed</b> date calender rule.
 /// </summary>
 /// <param name="name">The name of the holiday.</param>
 /// <param name="from">The first year in which the holiday occurs.</param>
 /// <param name="until">The last year in which the holiday occurs.</param>
 /// <param name="month">The month of the year where the holidays falls.</param>
 /// <param name="dayOfMonth">The day of the month where the holiday falls.</param>
 /// <param name="dateRoll">The <see cref="DateRoll"/> used to adjust dates.</param>
 public Fixed(string name, int from, int until, int month, int dayOfMonth, DateRoll dateRoll)
     : base(name, from, until)
 {
     this.month      = month;
     this.dayOfMonth = dayOfMonth;
     this.dateRoll   = dateRoll;
 }
Esempio n. 3
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();
        }
Esempio n. 4
0
        // --------------------------------------------------------------------
        /// <summary>
        /// Generates a set of dates according to schedule defined by a start date,
        /// an end date, an interval, roll convention and a calendar.
        /// </summary>
        /// <param name="start">The start date.</param>
        /// <param name="end">The end date.</param>
        /// <param name="frequency">The frequency of the schedule (e.g. 6M).</param>
        /// <param name="roll">The date roll convention or <c>null</c>.</param>
        /// <param name="calendar">The holiday calendar or <c>null</c>.</param>
        /// <returns>An array of calculated and adjusted dates.</returns>
        private static Date[] GenerateSchedule(Date start, Date end,
            Interval frequency, DateRoll roll, Calendar calendar)
        {
            Date		current = start;
            ArrayList	found	= new ArrayList ();
            Date []		dates;

            while (Less (current, end)) {
                Date		adjusted;

                if (roll != null)
                    adjusted = roll.Adjust (calendar, current);
                else
                    adjusted = current;

                if (!found.Contains (adjusted))
                    found.Add (adjusted);

                if (frequency.Period == Period.TERM) {
                    if (Equal (current, start))
                        current = end;
                    else
                        break;
                }
                else
                    current = current.Plus (frequency);
            }

            found.CopyTo (dates  = new Date [found.Count]);
            return (dates);
        }