Exemplo n.º 1
0
        private void DeleteHoliday()
        {
            string sMessageBoxText = "Do you want to delete this holiday?";
            string sCaption        = "Are you Sure?";

            MessageBoxButton btnMessageBox = MessageBoxButton.YesNo;
            MessageBoxImage  icnMessageBox = MessageBoxImage.Warning;

            MessageBoxResult rsltMessageBox = System.Windows.MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox);

            switch (rsltMessageBox)
            {
            case MessageBoxResult.Yes:
                HolidayManager    hm = new HolidayManager();
                HolidayCollection hc = new HolidayCollection();
                hm.DeleteHoliday(selectedHolidayId);
                hc.RetreiveAllHolidays();
                MessageBox.Show("Holiday successfully deleted.");
                Close();
                break;

            case MessageBoxResult.No:
                break;
            }
        }
Exemplo n.º 2
0
    public HolidayCollection FillHolidayByID(Int32 LeaveID)
    {
        HolidayCollection vc = new HolidayCollection();

        NewDAL.DBManager objDB = new DBManager();
        objDB.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["FeesManagementConn"].ConnectionString;
        objDB.DBManager(DataAccessLayer.DataProvider.SqlServer, objDB.ConnectionString);
        objDB.Open();
        objDB.CreateParameters(1);
        objDB.AddParameters(0, "InstituteID", 0, DbType.Int32);
        objDB.AddParameters(1, "SessionID", "", DbType.String);
        objDB.AddParameters(2, "LeaveID", LeaveID, DbType.Int32);
        IDataReader dr = (IDataReader)objDB.ExecuteReader(CommandType.StoredProcedure, "GetVenueForTTable");

        while (dr.Read())
        {
            TimeTableDM.HolidayDM objDM = new TimeTableDM.HolidayDM();
            objDM.LeaveID   = Education.DataHelper.GetInt(dr, "LeaveID");
            objDM.LeaveName = Education.DataHelper.GetString(dr, "LeaveName");
            objDM.Type      = Education.DataHelper.GetString(dr, "Type");
            objDM.Date      = Education.DataHelper.GetDateTime(dr, "Date");
            vc.Add(objDM);
        }
        objDB.Connection.Close();
        objDB.Dispose();
        return(vc);
    }
Exemplo n.º 3
0
        private void updateHoliday()
        {
            if (!string.IsNullOrEmpty(tbHolidayName.Text))
            {
                HolidayItem item = new HolidayItem();

                item._HOLIDAY_ID   = selectedHolidayId;
                item._HOLIDAY_NAME = tbHolidayName.Text;
                item._HOLIDAY_DATE = (DateTime)dpHolidayDate.SelectedDate;
                item._HOLIDAY_TYPE = cbHolidayType.SelectedValue.ToString();

                try
                {
                    HolidayManager hm = new HolidayManager();
                    hm.UpdateHoliday(item);
                    MessageBox.Show("Holiday successfully updated.");
                }
                catch (System.Exception)
                {
                    MessageBox.Show("Server not responding.");
                }

                HolidayCollection holidayList = new HolidayCollection();
                holidayList.RetreiveAllHolidays();

                Close();
            }
            else
            {
                MessageBox.Show("Please input holiday name.");
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = "Holiday Detection Demo";

            // Create a holiday collection with some default holidays, store it in the session, and bind it to
            // the data grid.
            if (!Page.IsPostBack)
            {
                HolidayCollection hc = (HolidayCollection)Session["Holidays"];

                // If we haven't been here before, create a new collection
                if (hc == null)
                {
                    hc = new HolidayCollection();
                    hc.AddStandardHolidays();
                    Session["Holidays"] = hc;
                }

                dgHolidays.DataSource = hc;
                dgHolidays.DataBind();

                txtFromYear.Text = (DateTime.Now.Year - 1).ToString();
                txtToYear.Text   = (DateTime.Now.Year + 6).ToString();
                txtTestDate.Text = DateTime.Today.ToString("d");
            }
        }
Exemplo n.º 5
0
        private void saveHoliday()
        {
            if (isHolidayValid())
            {
                HolidayItem item = new HolidayItem();

                item._HOLIDAY_NAME = tbHolidayName.Text;
                item._HOLIDAY_DATE = (DateTime)dpHolidayDate.SelectedDate;
                item._HOLIDAY_TYPE = cbHolidayType.SelectedValue.ToString();

                try
                {
                    HolidayManager hm = new HolidayManager();
                    hm.SaveHoliday(item);
                    MessageBox.Show("New Holiday added.");
                }
                catch (System.Exception)
                {
                    MessageBox.Show("Server not responding.");
                }

                HolidayCollection holidayList = new HolidayCollection();
                holidayList.RetreiveAllHolidays();

                Close();
            }
        }
Exemplo n.º 6
0
		protected void Page_Load(object sender, EventArgs e)
		{
            this.Page.Title = "Holiday Detection Demo";

            // Create a holiday collection with some default holidays, store it in the session, and bind it to
            // the data grid.
            if(!Page.IsPostBack)
            {
                HolidayCollection hc = (HolidayCollection)Session["Holidays"];

                // If we haven't been here before, create a new collection
                if(hc == null)
                {
                    hc = new HolidayCollection();
                    hc.AddStandardHolidays();
                    Session["Holidays"] = hc;
                }

                dgHolidays.DataSource = hc;
                dgHolidays.DataBind();

                txtFromYear.Text = (DateTime.Now.Year - 1).ToString();
                txtToYear.Text = (DateTime.Now.Year + 6).ToString();
                txtTestDate.Text = DateTime.Today.ToString("d");
            }
		}
Exemplo n.º 7
0
        public HolidayWindow()
        {
            InitializeComponent();
            HolidayCollection holicol = new HolidayCollection();

            holicol.RetreiveAllHolidays();
            currentDate = DateTime.Today;
            DisplayCurrentDate();
        }
 public void CanAddMultipleDatetime()
 {
     HolidayCollection.Clear();
     HolidayCollection.Add(new List <DateTime>()
     {
         DateTime.Now, DateTime.Now
     });
     Assert.AreEqual(HolidayCollection.Count(), 2);
 }
Exemplo n.º 9
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        public HolidayManager()
		{
			InitializeComponent();

            holidays = new HolidayCollection();

            this.Defaults = new HolidayCollection().AddStandardHolidays();

            loadSaveVisible = true;
		}
        public void GetAllHolidays()
        {
            HolidayCollection.Clear();
            HolidayCollection.Add(new List <DateTime>()
            {
                DateTime.Now, DateTime.Now
            });

            var holidayList = HolidayCollection.GetAll();

            Assert.AreEqual(HolidayCollection.Count(), holidayList.Count());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Update a holiday item in the collection
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgHolidays_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            HolidayCollection hc = (HolidayCollection)Session["Holidays"];

            if (!Page.IsValid)
            {
                return;
            }

            DropDownList cboMonth   = (DropDownList)e.Item.FindControl("cboMonth");
            RadioButton  rbFloating = (RadioButton)e.Item.FindControl("rbFloating");

            // Create holiday object and replace it in the collection
            if (rbFloating.Checked)
            {
                FloatingHoliday fl = new FloatingHoliday
                {
                    Month       = cboMonth.SelectedIndex + 1,
                    Description = ((TextBox)e.Item.FindControl("txtDescription")).Text,
                    Occurrence  = (DayOccurrence)((DropDownList)e.Item.FindControl("cboOccurrence")).SelectedIndex + 1,
                    Weekday     = (DayOfWeek)((DropDownList)e.Item.FindControl("cboDayOfWeek")).SelectedIndex,
                    Offset      = Convert.ToInt32(((TextBox)e.Item.FindControl("txtOffset")).Text)
                };

                hc[e.Item.ItemIndex] = fl;
            }
            else
            {
                // See if the day of the month is valid for the month.  We won't accept Feb 29th either.
                int day = Convert.ToInt32(((TextBox)e.Item.FindControl("txtDayOfMonth")).Text);

                if (day > DateTime.DaysInMonth(2007, cboMonth.SelectedIndex + 1))
                {
                    ((RangeValidator)e.Item.FindControl("rvDOM")).IsValid = false;
                    return;
                }

                FixedHoliday fx = new FixedHoliday
                {
                    Month           = cboMonth.SelectedIndex + 1,
                    Description     = ((TextBox)e.Item.FindControl("txtDescription")).Text,
                    AdjustFixedDate = ((CheckBox)e.Item.FindControl("chkAdjustDate")).Checked,
                    Day             = Convert.ToInt32(((TextBox)e.Item.FindControl("txtDayOfMonth")).Text)
                };

                hc[e.Item.ItemIndex] = fx;
            }

            dgHolidays.EditItemIndex = -1;
            dgHolidays.DataSource    = hc;
            dgHolidays.DataBind();
        }
Exemplo n.º 12
0
        //=====================================================================

        /// <summary>
        /// Test the entered date to see if it is a holiday as defined by the entries in the holiday manager's
        /// holiday collection.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnTestDate_Click(object sender, EventArgs e)
        {
            HolidayCollection holidays = new HolidayCollection(hmHolidays.Holidays);

            if(holidays.IsHoliday(dtpTestDate.Value))
            {
                MessageBox.Show("The test date is a holiday", "Found!", MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            else
                MessageBox.Show("The test date is not a holiday", "Not Found!", MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Cancel changes to a holiday in the collection
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgHolidays_CancelCommand(object source, DataGridCommandEventArgs e)
        {
            HolidayCollection hc = (HolidayCollection)Session["Holidays"];

            // If it was a new item, remove it
            if (String.IsNullOrWhiteSpace(hc[e.Item.ItemIndex].Description))
            {
                hc.RemoveAt(e.Item.ItemIndex);
            }

            dgHolidays.EditItemIndex = -1;
            dgHolidays.DataSource    = hc;
            dgHolidays.DataBind();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Load the holiday info from a file in the format selected by the user
        /// </summary>
        private void btnLoad_Click(object sender, System.EventArgs e)
        {
            using(OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title = LR.GetString("HMLoadTitle");
                dlg.DefaultExt = "xml";
                dlg.Filter = LR.GetString("HMFileDlgFilter");
                dlg.InitialDirectory = Environment.CurrentDirectory;

                if(dlg.ShowDialog() == DialogResult.OK)
                {
                    // Deserialize the holidays from a file of the selected format
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        using(FileStream fs = new FileStream(dlg.FileName, FileMode.Open))
                        {
                            XmlSerializer xs = new XmlSerializer(typeof(HolidayCollection));
                            holidays = (HolidayCollection)xs.Deserialize(fs);
                        }

                        this.LoadHolidayList();
                    }
                    catch(Exception ex)
                    {
                        System.Diagnostics.Debug.Write(ex.ToString());

                        string errorMsg = LR.GetString("HMLoadError", ex.Message);

                        if(ex.InnerException != null)
                        {
                            errorMsg += ex.InnerException.Message + "\n";

                            if(ex.InnerException.InnerException != null)
                                errorMsg += ex.InnerException.InnerException.Message;
                        }

                        System.Diagnostics.Debug.WriteLine(errorMsg);

                        MessageBox.Show(errorMsg, LR.GetString("HMErrorLoading"), MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Exemplo n.º 15
0
        //=====================================================================

        /// <summary>
        /// Test the entered date to see if it is a holiday as defined by the entries in the holiday manager's
        /// holiday collection.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnTestDate_Click(object sender, EventArgs e)
        {
            HolidayCollection holidays = new HolidayCollection(hmHolidays.Holidays);

            if (holidays.IsHoliday(dtpTestDate.Value))
            {
                MessageBox.Show("The test date is a holiday", "Found!", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("The test date is not a holiday", "Not Found!", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Test to see if the entered date is a holiday based on the set defined in the collection
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void btnIsHoliday_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                HolidayCollection hc = (HolidayCollection)Session["Holidays"];

                if (hc.IsHoliday(Convert.ToDateTime(txtTestDate.Text, CultureInfo.CurrentCulture)))
                {
                    lblIsHoliday.Text = "The test date is a defined holiday";
                }
                else
                {
                    lblIsHoliday.Text = "The test date is not a defined holiday";
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Find holidays defined by the holiday collection in the given range of years
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void btnFindHolidays_Click(object sender, EventArgs e)
        {
            HolidayCollection hc = (HolidayCollection)Session["Holidays"];
            int yearFrom, yearTo, tempYear;

            if (!Page.IsValid)
            {
                return;
            }

            yearFrom = Convert.ToInt32(txtFromYear.Text);
            yearTo   = Convert.ToInt32(txtToYear.Text);

            if (yearFrom > yearTo)
            {
                tempYear = yearFrom;
                yearFrom = yearTo;
                yearTo   = tempYear;
            }

            // Limit the range to 50 years in the web app to prevent using too many resources on the server
            if (yearTo > yearFrom + 49)
            {
                yearTo = yearFrom + 49;
            }

            txtFromYear.Text = yearFrom.ToString();
            txtToYear.Text   = yearTo.ToString();

            lbDates.Items.Clear();
            var dcDates = hc.HolidaysBetween(yearFrom, yearTo).ToList();

            if (dcDates.Count > 0)
            {
                foreach (DateTime dt in dcDates)
                {
                    lbDates.Items.Add(String.Format("{0:d} - {1}", dt, hc.HolidayDescription(dt)));
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Delete a holiday from the collection
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgHolidays_DeleteCommand(object source, DataGridCommandEventArgs e)
        {
            // Save changes to the edited item if it isn't the one being deleted
            if (dgHolidays.EditItemIndex != -1 && dgHolidays.EditItemIndex != e.Item.ItemIndex)
            {
                Page.Validate();
                dgHolidays_UpdateCommand(source, new DataGridCommandEventArgs(
                                             dgHolidays.Items[dgHolidays.EditItemIndex], e.CommandSource, e));

                if (!Page.IsValid)
                {
                    return;
                }
            }

            HolidayCollection hc = (HolidayCollection)Session["Holidays"];

            hc.RemoveAt(e.Item.ItemIndex);
            dgHolidays.EditItemIndex = -1;
            dgHolidays.DataSource    = hc;
            dgHolidays.DataBind();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Find all holidays in the given range of years using the entries defined in the holiday manager's
        /// holiday collection.  The found dates and descriptions are loaded into the grid view.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnFind_Click(object sender, EventArgs e)
        {
            HolidayCollection holidays = new HolidayCollection(hmHolidays.Holidays);
            int fromYear, toYear, year;

            fromYear = (int)udcFromYear.Value;
            toYear   = (int)udcToYear.Value;

            if (fromYear > toYear)
            {
                year              = fromYear;
                fromYear          = toYear;
                toYear            = year;
                udcFromYear.Value = fromYear;
                udcToYear.Value   = toYear;
            }

            this.Cursor = Cursors.WaitCursor;

            dgvDatesFound.DataSource = holidays.HolidaysBetween(fromYear, toYear).OrderBy(d => d).Select(d =>
                                                                                                         new ListItem(d, holidays.HolidayDescription(d))).ToList();

            this.Cursor = Cursors.Default;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Bind data to the edit item template.  Since the holiday collection uses the abstract class, we'll
        /// bind data in here rather than in the HTML since we have to determine the type first.
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgHolidays_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.EditItem)
            {
                // The RecurOptsDataSource class contains static methods that return lists of common values we
                // can uses as the data sources for these drop down lists.
                DropDownList cboMonth = (DropDownList)e.Item.FindControl("cboMonth");
                cboMonth.DataSource     = RecurOptsDataSource.MonthsOfYear;
                cboMonth.DataTextField  = "Display";
                cboMonth.DataValueField = "Value";
                cboMonth.DataBind();

                DropDownList cboOccurrence = (DropDownList)e.Item.FindControl("cboOccurrence");
                cboOccurrence.DataSource     = RecurOptsDataSource.DayOccurrences;
                cboOccurrence.DataTextField  = "Display";
                cboOccurrence.DataValueField = "Value";
                cboOccurrence.DataBind();

                DropDownList cboDayOfWeek = (DropDownList)e.Item.FindControl("cboDayOfWeek");
                cboDayOfWeek.DataSource     = RecurOptsDataSource.DayOfWeek;
                cboDayOfWeek.DataTextField  = "Display";
                cboDayOfWeek.DataValueField = "Value";
                cboDayOfWeek.DataBind();

                RadioButton rbFloating = (RadioButton)e.Item.FindControl("rbFloating");
                RadioButton rbFixed    = (RadioButton)e.Item.FindControl("rbFixed");

                HolidayCollection hc = (HolidayCollection)Session["Holidays"];

                if (hc[e.Item.ItemIndex] is FloatingHoliday)
                {
                    FloatingHoliday fl = (FloatingHoliday)hc[e.Item.ItemIndex];

                    cboOccurrence.SelectedIndex = (int)fl.Occurrence - 1;
                    cboDayOfWeek.SelectedIndex  = (int)fl.Weekday;
                    ((TextBox)e.Item.FindControl("txtOffset")).Text =
                        ((fl.Offset < -999) ? -999 : (fl.Offset > 999) ? 999 : fl.Offset).ToString();

                    rbFloating.Checked = true;
                    rbFixed.Checked    = false;
                    ((TextBox)e.Item.FindControl("txtDayOfMonth")).Enabled              =
                        ((RequiredFieldValidator)e.Item.FindControl("rfvDOM")).Enabled  =
                            ((RangeValidator)e.Item.FindControl("rvDOM")).Enabled       =
                                ((CheckBox)e.Item.FindControl("chkAdjustDate")).Enabled = false;
                    ((TextBox)e.Item.FindControl("txtDayOfMonth")).CssClass             = "Disabled";
                }
                else
                {
                    FixedHoliday fx = (FixedHoliday)hc[e.Item.ItemIndex];

                    ((TextBox)e.Item.FindControl("txtOffset")).Text         = "0";
                    ((TextBox)e.Item.FindControl("txtDayOfMonth")).Text     = fx.Day.ToString();
                    ((CheckBox)e.Item.FindControl("chkAdjustDate")).Checked = fx.AdjustFixedDate;

                    rbFloating.Checked    = false;
                    rbFixed.Checked       = true;
                    cboOccurrence.Enabled = cboDayOfWeek.Enabled =
                        ((TextBox)e.Item.FindControl("txtOffset")).Enabled =
                            ((RequiredFieldValidator)e.Item.FindControl("rfvOffset")).Enabled =
                                ((RangeValidator)e.Item.FindControl("rvOffset")).Enabled      = false;
                    cboOccurrence.CssClass = cboDayOfWeek.CssClass =
                        ((TextBox)e.Item.FindControl("txtOffset")).CssClass = "Disabled";
                }

                cboMonth.SelectedIndex = hc[e.Item.ItemIndex].Month - 1;
                ((TextBox)e.Item.FindControl("txtDescription")).Text = hc[e.Item.ItemIndex].Description;
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Find all holidays in the given range of years using the entries defined in the holiday manager's
        /// holiday collection.  The found dates and descriptions are loaded into the grid view.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnFind_Click(object sender, EventArgs e)
        {
            HolidayCollection holidays = new HolidayCollection(hmHolidays.Holidays);
            int fromYear, toYear, year;

            fromYear = (int)udcFromYear.Value;
            toYear = (int)udcToYear.Value;

            if(fromYear > toYear)
            {
                year = fromYear;
                fromYear = toYear;
                toYear = year;
                udcFromYear.Value = fromYear;
                udcToYear.Value = toYear;
            }

            this.Cursor = Cursors.WaitCursor;

            dgvDatesFound.DataSource = holidays.HolidaysBetween(fromYear, toYear).OrderBy(d => d).Select(d =>
                new ListItem(d, holidays.HolidayDescription(d))).ToList();

            this.Cursor = Cursors.Default;
        }
Exemplo n.º 22
0
		static void Main(string[] args)
		{
            DateTime testDate, nextDate;
            HashSet<DateTime> holidayDates;
            DateTimeCollection recurDates;
            int yearFrom, yearTo, idx;

            if(args.GetUpperBound(0) < 1)
            {
                Console.WriteLine("Specify a starting and ending year");
                return;
            }

            try
            {
                yearFrom = Convert.ToInt32(args[0]);
                yearTo = Convert.ToInt32(args[1]);

                if(yearFrom < 1)
                    yearFrom = 1;

                if(yearFrom > 9999)
                    yearFrom = 9999;

                if(yearTo < 1)
                    yearTo = 1;

                if(yearTo > 9999)
                    yearTo = 9999;

                if(yearFrom > yearTo)
                {
                    idx = yearFrom;
                    yearFrom = yearTo;
                    yearTo = idx;
                }
            }
            catch
            {
                Console.WriteLine("Invalid year specified on command line");
                return;
            }

            // Test DateUtils.CalculateOccurrenceDate
            Console.WriteLine("Fourth weekday in January 2004: {0:d}",
                DateUtils.CalculateOccurrenceDate(2004, 1, DayOccurrence.Fourth, DaysOfWeek.Weekdays, 0));

            Console.WriteLine("Fourth weekday in January 2004 + 2: {0:d}",
                DateUtils.CalculateOccurrenceDate(2004, 1, DayOccurrence.Fourth, DaysOfWeek.Weekdays, 2));

            Console.WriteLine("Last weekend day in January 2004: {0:d}",
                DateUtils.CalculateOccurrenceDate(2004, 1, DayOccurrence.Last, DaysOfWeek.Weekends, 0));

            Console.WriteLine("Last weekend day in January 2004 + 2: {0:d}",
                DateUtils.CalculateOccurrenceDate(2004, 1, DayOccurrence.Last, DaysOfWeek.Weekends, 2));

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test DateUtils.DateFromWeek(), DateUtils.WeeksInYear(), and DateUtils.WeekFromDate()
            DateTime weekFrom, weekTo;
            int year;

            Console.WriteLine("Week start = Monday");
            DayOfWeek dow = DayOfWeek.Monday;

            for(year = 1998; year < 2010; year++)
            {
                for(idx = 1; idx < 54; idx++)
                    if(idx != 53 || DateUtils.WeeksInYear(year, dow) == 53)
                    {
                        weekFrom = DateUtils.DateFromWeek(year, idx, dow, 0);
                        weekTo = DateUtils.DateFromWeek(year, idx, dow, 6);

                        Console.WriteLine("{0} Week {1}: {2:d} - {3:d}  {4}", year, idx, weekFrom, weekTo,
                            DateUtils.WeekFromDate(weekFrom.AddDays(3), dow));
                    }

                // Pause to review output
                Console.WriteLine("Press ENTER to continue");
                Console.ReadLine();
            }

            // Test DateUtils.EasterSunday()
            Console.WriteLine("Easter - Gregorian");

            for(idx = yearFrom; idx <= yearTo; idx += 3)
            {
                testDate = DateUtils.EasterSunday(idx, EasterMethod.Gregorian);
                Console.Write("{0}    {1}/{2:00}            ", idx, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 1, EasterMethod.Gregorian);
                Console.Write("{0}    {1}/{2:00}            ", idx + 1, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 2, EasterMethod.Gregorian);
                Console.WriteLine("{0}    {1}/{2:00}", idx + 2, testDate.Month, testDate.Day);
            }

            Console.WriteLine("\nEaster - Julian");

            for(idx = yearFrom; idx <= yearTo; idx += 3)
            {
                testDate = DateUtils.EasterSunday(idx, EasterMethod.Julian);
                Console.Write("{0}    {1}/{2:00}            ", idx, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 1, EasterMethod.Julian);
                Console.Write("{0}    {1}/{2:00}            ", idx + 1, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 2, EasterMethod.Julian);
                Console.WriteLine("{0}    {1}/{2:00}", idx + 2, testDate.Month, testDate.Day);
            }

            Console.WriteLine("\nEaster - Orthodox");

            for(idx = yearFrom; idx <= yearTo; idx += 3)
            {
                testDate = DateUtils.EasterSunday(idx, EasterMethod.Orthodox);
                Console.Write("{0}    {1}/{2:00}            ", idx, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 1, EasterMethod.Orthodox);
                Console.Write("{0}    {1}/{2:00}            ", idx + 1, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 2, EasterMethod.Orthodox);
                Console.WriteLine("{0}    {1}/{2:00}", idx + 2, testDate.Month, testDate.Day);
            }

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test DateUtils.FromISO8601String and DateUtils.FromISO8601TimeZone
            Console.WriteLine("Expressed in Universal Time");

            Console.WriteLine("20040314 = {0}", DateUtils.FromISO8601String("20040314", false));
            Console.WriteLine("20040314T10 = {0}", DateUtils.FromISO8601String("20040314T10", false));
            Console.WriteLine("20040314T1025 = {0}", DateUtils.FromISO8601String("20040314T1025", false));
            Console.WriteLine("20040314T102531 = {0}", DateUtils.FromISO8601String("20040314T102531", false));
            Console.WriteLine("20040314T102531.123 = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("20040314T102531.123", false));
            Console.WriteLine("20040314T102531.98Z = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("20040314T102531.98Z", false));
            Console.WriteLine("20040314T102531-04 = {0}", DateUtils.FromISO8601String("20040314T102531-04", false));
            Console.WriteLine("20040314T102531.123+0830 = {0}",
                DateUtils.FromISO8601String("20040314T102531.123+0830", false));

            Console.WriteLine("\n2004-03-14 = {0}", DateUtils.FromISO8601String("2004-03-14", false));
            Console.WriteLine("2004-03-14T10 = {0}", DateUtils.FromISO8601String("2004-03-14T10", false));
            Console.WriteLine("2004-03-14T10:25 = {0}", DateUtils.FromISO8601String("2004-03-14T10:25", false));
            Console.WriteLine("2004-03-14T10:25:31 = {0}", DateUtils.FromISO8601String("2004-03-14T10:25:31", false));
            Console.WriteLine("2004-03-14T10:25:31.123 = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31.123", false));
            Console.WriteLine("2004-03-14T10:25:31.98Z = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31.98Z", false));
            Console.WriteLine("2004-03-14T10:25:31-04 = {0}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31-04", false));
            Console.WriteLine("2004-03-14T10:25:31+08:30 = {0}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31+08:30", false));

            // Test DateUtils.FromISO8601String and DateUtils.FromISO8601TimeZone
            Console.WriteLine("\nExpressed in Local Time");

            Console.WriteLine("20040314 = {0}", DateUtils.FromISO8601String("20040314", true));
            Console.WriteLine("20040314T10 = {0}", DateUtils.FromISO8601String("20040314T10", true));
            Console.WriteLine("20040314T1025 = {0}", DateUtils.FromISO8601String("20040314T1025", true));
            Console.WriteLine("20040314T102531 = {0}", DateUtils.FromISO8601String("20040314T102531", true));
            Console.WriteLine("20040314T102531.123 = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("20040314T102531.123", true));
            Console.WriteLine("20040314T102531.98Z = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("20040314T102531.98Z", true));
            Console.WriteLine("20040314T102531-04 = {0}", DateUtils.FromISO8601String("20040314T102531-04", true));
            Console.WriteLine("20040314T102531.123+0830 = {0}",
                DateUtils.FromISO8601String("20040314T102531.123+0830", true));

            Console.WriteLine("\n2004-03-14 = {0}", DateUtils.FromISO8601String("2004-03-14", true));
            Console.WriteLine("2004-03-14T10 = {0}", DateUtils.FromISO8601String("2004-03-14T10", true));
            Console.WriteLine("2004-03-14T10:25 = {0}", DateUtils.FromISO8601String("2004-03-14T10:25", true));
            Console.WriteLine("2004-03-14T10:25:31 = {0}", DateUtils.FromISO8601String("2004-03-14T10:25:31", true));
            Console.WriteLine("2004-03-14T10:25:31.123 = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31.123", true));
            Console.WriteLine("2004-03-14T10:25:31.98Z = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31.98Z", true));
            Console.WriteLine("2004-03-14T10:25:31-04 = {0}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31-04", true));
            Console.WriteLine("2004-03-14T10:25:31+08:30 = {0}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31+08:30", true));

            TimeSpan ts = DateUtils.FromISO8601TimeZone("+08");

            Console.WriteLine("\n+08 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("-08");

            Console.WriteLine("-08 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("-0830");

            Console.WriteLine("-0830 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("+08:30");

            Console.WriteLine("+08:30 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test the Duration class
            Console.WriteLine("Assumptions: 1 year = {0} days, 1 month = {1} days\n", Duration.DaysInOneYear,
                Duration.DaysInOneMonth);

            Duration d = new Duration("P1Y2M3W4DT5H6M7S");

            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0}", d.ToString());
            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToString(Duration.MaxUnit.Months));

            d = new Duration("P10Y11MT16M12S");

            Console.WriteLine("P10Y11MT16M12S = {0}", d.ToString());

            d = new Duration("P5M2DT16M");

            Console.WriteLine("P5M2DT16M = {0}", d.ToString());

            d = new Duration("P7W");

            Console.WriteLine("P7W = {0}", d.ToString());
            Console.WriteLine("P7W = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("P7W2D");

            Console.WriteLine("P7W2D = {0}", d.ToString());
            Console.WriteLine("P7W2D = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W2D = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("P5DT2S");

            Console.WriteLine("P5DT2S = {0}", d.ToString());

            d = new Duration("PT24H");

            Console.WriteLine("PT24H = {0}", d.ToString());
            Console.WriteLine("PT24H = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H = {0} (max units = seconds)",  d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("PT24H3M2S");

            Console.WriteLine("PT24H3M2S = {0}", d.ToString());
            Console.WriteLine("PT24H3M2S = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H3M2S = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H3M2S = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("PT1H10M20S");

            Console.WriteLine("PT1H10M20S = {0}", d.ToString());

            d = new Duration("PT5M20S");

            Console.WriteLine("PT5M20S = {0}", d.ToString());

            d = new Duration("PT5S");

            Console.WriteLine("PT5S = {0}", d.ToString());

            d = new Duration("P0Y0M0W0DT0H0M0S");

            Console.WriteLine("P0Y0M0W0DT0H0M0S = {0}", d.ToString());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            d = new Duration("-P1Y2M3W4DT5H6M7S");

            Console.WriteLine("\n-P1Y2M3W4DT5H6M7S = {0}", d.ToString());
            Console.WriteLine("-P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToString(Duration.MaxUnit.Months));

            d = new Duration("-P10Y11MT16M12S");

            Console.WriteLine("-P10Y11MT16M12S = {0}", d.ToString());

            d = new Duration("-P5M2DT16M");

            Console.WriteLine("-P5M2DT16M = {0}", d.ToString());

            d = new Duration("-P7W");

            Console.WriteLine("-P7W = {0}", d.ToString());
            Console.WriteLine("-P7W = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("-P7W2D");

            Console.WriteLine("-P7W2D = {0}", d.ToString());
            Console.WriteLine("-P7W2D = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W2D = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("-P5DT2S");

            Console.WriteLine("-P5DT2S = {0}", d.ToString());

            d = new Duration("-PT24H");

            Console.WriteLine("-PT24H = {0}", d.ToString());
            Console.WriteLine("-PT24H = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("-PT24H3M2S");

            Console.WriteLine("-PT24H3M2S = {0}", d.ToString());
            Console.WriteLine("-PT24H3M2S = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H3M2S = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H3M2S = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("-PT1H10M20S");

            Console.WriteLine("-PT1H10M20S = {0}", d.ToString());

            d = new Duration("-PT5M20S");

            Console.WriteLine("-PT5M20S = {0}", d.ToString());

            d = new Duration("-PT5S");

            Console.WriteLine("-PT5S = {0}", d.ToString());

            d = new Duration("-P0Y0M0W0DT0H0M0S");

            Console.WriteLine("-P0Y0M0W0DT0H0M0S = {0}", d.ToString());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test the ToDescription() methods
            d = new Duration("P1Y2M3W4DT5H6M7S");

            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0}", d.ToDescription());
            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToDescription(Duration.MaxUnit.Months));

            d = new Duration("P10Y11MT16M12S");

            Console.WriteLine("P10Y11MT16M12S = {0}", d.ToDescription());

            d = new Duration("P5M2DT16M");

            Console.WriteLine("P5M2DT16M = {0}", d.ToDescription());

            d = new Duration("P7W");

            Console.WriteLine("P7W = {0}", d.ToDescription());
            Console.WriteLine("P7W = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("P7W2D");

            Console.WriteLine("P7W2D = {0}", d.ToDescription());
            Console.WriteLine("P7W2D = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W2D = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("P5DT2S");

            Console.WriteLine("P5DT2S = {0}", d.ToDescription());

            d = new Duration("PT24H");

            Console.WriteLine("PT24H = {0}", d.ToDescription());
            Console.WriteLine("PT24H = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("PT24H3M2S");

            Console.WriteLine("PT24H3M2S = {0}", d.ToDescription());
            Console.WriteLine("PT24H3M2S = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H3M2S = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H3M2S = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("PT1H10M20S");

            Console.WriteLine("PT1H10M20S = {0}", d.ToDescription());

            d = new Duration("PT5M20S");

            Console.WriteLine("PT5M20S = {0}", d.ToDescription());

            d = new Duration("PT5S");

            Console.WriteLine("PT5S = {0}", d.ToDescription());

            d = new Duration("P0Y0M0W0DT0H0M0S");

            Console.WriteLine("P0Y0M0W0DT0H0M0S = {0}", d.ToDescription());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            d = new Duration("-P1Y2M3W4DT5H6M7S");

            Console.WriteLine("\n-P1Y2M3W4DT5H6M7S = {0}", d.ToDescription());
            Console.WriteLine("-P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToDescription(Duration.MaxUnit.Months));

            d = new Duration("-P10Y11MT16M12S");

            Console.WriteLine("-P10Y11MT16M12S = {0}", d.ToDescription());

            d = new Duration("-P5M2DT16M");

            Console.WriteLine("-P5M2DT16M = {0}", d.ToDescription());

            d = new Duration("-P7W");

            Console.WriteLine("-P7W = {0}", d.ToDescription());
            Console.WriteLine("-P7W = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("-P7W2D");

            Console.WriteLine("-P7W2D = {0}", d.ToDescription());
            Console.WriteLine("-P7W2D = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W2D = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("-P5DT2S");

            Console.WriteLine("-P5DT2S = {0}", d.ToDescription());

            d = new Duration("-PT24H");

            Console.WriteLine("-PT24H = {0}", d.ToDescription());
            Console.WriteLine("-PT24H = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("-PT24H3M2S");

            Console.WriteLine("-PT24H3M2S = {0}", d.ToDescription());
            Console.WriteLine("-PT24H3M2S = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H3M2S = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H3M2S = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("-PT1H10M20S");

            Console.WriteLine("-PT1H10M20S = {0}", d.ToDescription());

            d = new Duration("-PT5M20S");

            Console.WriteLine("-PT5M20S = {0}", d.ToDescription());

            d = new Duration("-PT5S");

            Console.WriteLine("-PT5S = {0}", d.ToDescription());

            d = new Duration("-P0Y0M0W0DT0H0M0S");

            Console.WriteLine("-P0Y0M0W0DT0H0M0S = {0}", d.ToDescription());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Create a set of fixed and floating holidays
            HolidayCollection holidays = new HolidayCollection();

            holidays.AddFixed(1, 1, true, "New Year's Day");
            holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 1, 0, "Martin Luther King Day");
            holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 2, 0, "President's Day");
            holidays.AddFloating(DayOccurrence.Last, DayOfWeek.Monday, 5, 0, "Memorial Day");
            holidays.AddFixed(7, 4, true, "Independence Day");
            holidays.AddFloating(DayOccurrence.First, DayOfWeek.Monday, 9, 0, "Labor Day");
            holidays.AddFixed(11, 11, true, "Veteran's Day");
            holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 0, "Thanksgiving Day");
            holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 1, "Day After Thanksgiving");
            holidays.AddFixed(12, 25, true, "Christmas Day");

            // Serialize the holidays to a file
            try
            {
                // XML
                using(var fs = new FileStream("Holidays.xml", FileMode.Create))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(HolidayCollection));
                    xs.Serialize(fs, holidays);

                    Console.WriteLine("Holidays saved to Holidays.xml");
                }

                // SOAP
                using(var fs = new FileStream("Holidays.soap", FileMode.Create))
                {
                    SoapFormatter sf = new SoapFormatter();

                    // SOAP doesn't support generics directly so use an array
                    sf.Serialize(fs, holidays.ToArray());

                    Console.WriteLine("Holidays saved to Holidays.soap");
                }

                // Binary
                using(var fs = new FileStream("Holidays.bin", FileMode.Create))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, holidays);

                    Console.WriteLine("Holidays saved to Holidays.bin\n");
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unable to save holidays:\n{0}", ex.Message);

                if(ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if(ex.InnerException.InnerException != null)
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                }
            }

            // Delete the collection and read it back in
            holidays = null;

            try
            {
                // XML
                using(var fs = new FileStream("Holidays.xml", FileMode.Open))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(HolidayCollection));
                    holidays = (HolidayCollection)xs.Deserialize(fs);

                    Console.WriteLine("Holidays retrieved from Holidays.xml");
                }

                // SOAP
                using(var fs = new FileStream("Holidays.soap", FileMode.Open))
                {
                    SoapFormatter sf = new SoapFormatter();

                    // As noted, SOAP doesn't support generics to an array is used instead
                    holidays = new HolidayCollection((Holiday[])sf.Deserialize(fs));

                    Console.WriteLine("Holidays retrieved from Holidays.soap");
                }

                // Binary
                using(var fs = new FileStream("Holidays.bin", FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    holidays = (HolidayCollection)bf.Deserialize(fs);

                    Console.WriteLine("Holidays retrieved from Holidays.bin\n");
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unable to load holidays:\n{0}", ex.Message);

                if(ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if(ex.InnerException.InnerException != null)
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                }
            }

            // Display the holidays added to the list
            Console.WriteLine("Holidays on file.  Is Holiday should be true for all.");

            foreach(Holiday hol in holidays)
                Console.WriteLine("Holiday Date: {0:d}   Is Holiday: {1}  Description: {2}",
                    hol.ToDateTime(yearFrom), holidays.IsHoliday(hol.ToDateTime(yearFrom)), hol.Description);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Display holidays found in each year specified using the IsHoliday method
            Console.WriteLine("Looking for holidays using the IsHoliday method");

            testDate = new DateTime(yearFrom, 1, 1);

            while(testDate.Year <= yearTo)
            {
                if(holidays.IsHoliday(testDate))
                    Console.WriteLine("Found holiday: {0:d} {1}", testDate, holidays.HolidayDescription(testDate));

                testDate = testDate.AddDays(1);

                // Stop after each year to review output
                if(testDate.Month == 1 && testDate.Day == 1)
                {
                    Console.WriteLine("Press ENTER to continue");
                    Console.ReadLine();
                }
            }

            // One more time, but use a hash set using the dates returned by the HolidaysBetween() method.  For
            // bulk comparisons, this is faster than the above procedure using the IsHoliday method.
            Console.WriteLine("Looking for holidays using HolidaysBetween");

            holidayDates = new HashSet<DateTime>(holidays.HolidaysBetween(yearFrom, yearTo));

            if(holidayDates.Count != 0)
            {
                testDate = new DateTime(yearFrom, 1, 1);

                while(testDate.Year <= yearTo)
                {
                    if(holidayDates.Contains(testDate))
                        Console.WriteLine("Found holiday: {0:d} {1}", testDate, holidays.HolidayDescription(testDate));

                    testDate = testDate.AddDays(1);

                    // Stop after each year to review output
                    if(testDate.Month == 1 && testDate.Day == 1)
                    {
                        Console.WriteLine("Press ENTER to continue");
                        Console.ReadLine();
                    }
                }
            }

            //=================================================================

            // Test recurrence
            Recurrence rRecur = new Recurrence();
            Recurrence.Holidays.AddRange(holidays);

            // Disallow occurrences on any of the defined holidays
            rRecur.CanOccurOnHoliday = false;

            testDate = new DateTime(yearFrom, 1, 1);

            // Test daily recurrence
            rRecur.StartDateTime = testDate;
            rRecur.RecurUntil = testDate.AddMonths(1);   // For the enumerator
            rRecur.RecurDaily(2);

            // Serialize the recurrence to a file
            try
            {
                // XML
                using(var fs = new FileStream("Recurrence.xml", FileMode.Create))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Recurrence));
                    xs.Serialize(fs, rRecur);

                    Console.WriteLine("Recurrence saved to Recurrence.xml");
                }

                // SOAP
                using(var fs = new FileStream("Recurrence.soap", FileMode.Create))
                {
                    SoapFormatter sf = new SoapFormatter();
                    sf.Serialize(fs, rRecur);

                    Console.WriteLine("Recurrence saved to Recurrence.soap");
                }

                // Binary
                using(var fs = new FileStream("Recurrence.bin", FileMode.Create))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, rRecur);

                    Console.WriteLine("Recurrence saved to Recurrence.bin\n");
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unable to save recurrence:\n{0}", ex.Message);

                if(ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if(ex.InnerException.InnerException != null)
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                }
            }

            // Deserialize the recurrence from a file
            rRecur = null;

            try
            {
                // XML
                using(var fs = new FileStream("Recurrence.xml", FileMode.Open))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Recurrence));
                    rRecur = (Recurrence)xs.Deserialize(fs);

                    Console.WriteLine("Recurrence restored from Recurrence.xml");
                }

                // SOAP
                using(var fs = new FileStream("Recurrence.soap", FileMode.Open))
                {
                    SoapFormatter sf = new SoapFormatter();
                    rRecur = (Recurrence)sf.Deserialize(fs);

                    Console.WriteLine("Recurrence retrieved from Recurrence.soap");
                }

                // Binary
                using(var fs = new FileStream("Recurrence.bin", FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    rRecur = (Recurrence)bf.Deserialize(fs);

                    Console.WriteLine("Recurrence retrieved from Recurrence.bin\n");
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unable to restore recurrence:\n{0}", ex.Message);

                if(ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if(ex.InnerException.InnerException != null)
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                }
            }

            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(1));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Daily recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Daily recurrence on: {0:d}", dt);

            // Test NextInstance().  This isn't the most efficient way of searching for lots of dates but is
            // useful for one-off searches.
            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Daily recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test weekly recurrence
            rRecur.StartDateTime = testDate;
            rRecur.RecurWeekly(1, DaysOfWeek.Monday | DaysOfWeek.Wednesday);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(1));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Weekly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Weekly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Weekly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test monthly recurrence (option 1)
            rRecur.StartDateTime = testDate;
            rRecur.RecurUntil = testDate.AddMonths(12);   // For the enumerator
            rRecur.RecurMonthly(15, 2);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(12));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Monthly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Monthly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Monthly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test monthly recurrence (option 2)
            rRecur.RecurMonthly(DayOccurrence.Third, DaysOfWeek.Thursday, 3);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(12));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Monthly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Monthly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Monthly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test monthly recurrence (option 3 - a variation of option 2)
            rRecur.RecurMonthly(DayOccurrence.Third, DaysOfWeek.Weekends, 2);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(12));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Monthly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Monthly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Monthly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test yearly recurrence (option 1)
            rRecur.StartDateTime = testDate;
            rRecur.RecurUntil = testDate.AddYears(5);   // For the enumerator
            rRecur.RecurYearly(5, 24, 1);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddYears(5));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Yearly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Yearly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Yearly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test yearly recurrence (option 2)
            rRecur.RecurYearly(DayOccurrence.Last, DaysOfWeek.Sunday, 9, 2);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddYears(5));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Yearly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Yearly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Yearly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test yearly recurrence (option 3 - a variation of option 2)
            rRecur.RecurYearly(DayOccurrence.Last, DaysOfWeek.Weekdays, 7, 1);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddYears(5));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach(DateTime dt in recurDates)
                Console.WriteLine("(Collection) Yearly recurrence on: {0:d}", dt);

            foreach(DateTime dt in rRecur)
                Console.WriteLine("(Enumerator) Yearly recurrence on: {0:d}", dt);

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if(nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Yearly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }

            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            DateTime           testDate, nextDate;
            HashSet <DateTime> holidayDates;
            DateTimeCollection recurDates;
            int yearFrom, yearTo, idx;

            if (args.Length != 2)
            {
                Console.WriteLine("Using current year +/- 4 years for testing\r\n");

                yearFrom = DateTime.Today.Year - 4;
                yearTo   = yearFrom + 8;
            }
            else
            {
                try
                {
                    yearFrom = Convert.ToInt32(args[0]);
                    yearTo   = Convert.ToInt32(args[1]);

                    if (yearFrom < 1)
                    {
                        yearFrom = 1;
                    }

                    if (yearFrom > 9999)
                    {
                        yearFrom = 9999;
                    }

                    if (yearTo < 1)
                    {
                        yearTo = 1;
                    }

                    if (yearTo > 9999)
                    {
                        yearTo = 9999;
                    }

                    if (yearFrom > yearTo)
                    {
                        idx      = yearFrom;
                        yearFrom = yearTo;
                        yearTo   = idx;
                    }
                }
                catch
                {
                    Console.WriteLine("Invalid year specified on command line");
                    return;
                }
            }

            // Test DateUtils.CalculateOccurrenceDate
            Console.WriteLine("Fourth weekday in January 2018: {0:d}",
                              DateUtils.CalculateOccurrenceDate(2018, 1, DayOccurrence.Fourth, DaysOfWeek.Weekdays, 0));

            Console.WriteLine("Fourth weekday in January 2018 + 2: {0:d}",
                              DateUtils.CalculateOccurrenceDate(2018, 1, DayOccurrence.Fourth, DaysOfWeek.Weekdays, 2));

            Console.WriteLine("Last weekend day in January 2018: {0:d}",
                              DateUtils.CalculateOccurrenceDate(2018, 1, DayOccurrence.Last, DaysOfWeek.Weekends, 0));

            Console.WriteLine("Last weekend day in January 2018 + 2: {0:d}",
                              DateUtils.CalculateOccurrenceDate(2018, 1, DayOccurrence.Last, DaysOfWeek.Weekends, 2));

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test DateUtils.DateFromWeek(), DateUtils.WeeksInYear(), and DateUtils.WeekFromDate()
            DateTime weekFrom, weekTo;
            int      year;

            Console.WriteLine("Week start = Monday");
            DayOfWeek dow = DayOfWeek.Monday;

            for (year = yearFrom; year <= yearTo; year++)
            {
                for (idx = 1; idx < 54; idx++)
                {
                    if (idx != 53 || DateUtils.WeeksInYear(year, dow) == 53)
                    {
                        weekFrom = DateUtils.DateFromWeek(year, idx, dow, 0);
                        weekTo   = DateUtils.DateFromWeek(year, idx, dow, 6);

                        Console.WriteLine("{0} Week {1}: {2:d} - {3:d}  {4}", year, idx, weekFrom, weekTo,
                                          DateUtils.WeekFromDate(weekFrom.AddDays(3), dow));
                    }
                }

                // Pause to review output
                Console.WriteLine("Press ENTER to continue");
                Console.ReadLine();
            }

            // Test DateUtils.EasterSunday()
            Console.WriteLine("Easter - Gregorian");

            for (idx = yearFrom; idx <= yearTo; idx += 3)
            {
                testDate = DateUtils.EasterSunday(idx, EasterMethod.Gregorian);
                Console.Write("{0}    {1}/{2:00}            ", idx, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 1, EasterMethod.Gregorian);
                Console.Write("{0}    {1}/{2:00}            ", idx + 1, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 2, EasterMethod.Gregorian);
                Console.WriteLine("{0}    {1}/{2:00}", idx + 2, testDate.Month, testDate.Day);
            }

            Console.WriteLine("\nEaster - Julian");

            for (idx = yearFrom; idx <= yearTo; idx += 3)
            {
                testDate = DateUtils.EasterSunday(idx, EasterMethod.Julian);
                Console.Write("{0}    {1}/{2:00}            ", idx, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 1, EasterMethod.Julian);
                Console.Write("{0}    {1}/{2:00}            ", idx + 1, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 2, EasterMethod.Julian);
                Console.WriteLine("{0}    {1}/{2:00}", idx + 2, testDate.Month, testDate.Day);
            }

            Console.WriteLine("\nEaster - Orthodox");

            for (idx = yearFrom; idx <= yearTo; idx += 3)
            {
                testDate = DateUtils.EasterSunday(idx, EasterMethod.Orthodox);
                Console.Write("{0}    {1}/{2:00}            ", idx, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 1, EasterMethod.Orthodox);
                Console.Write("{0}    {1}/{2:00}            ", idx + 1, testDate.Month, testDate.Day);

                testDate = DateUtils.EasterSunday(idx + 2, EasterMethod.Orthodox);
                Console.WriteLine("{0}    {1}/{2:00}", idx + 2, testDate.Month, testDate.Day);
            }

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test DateUtils.FromISO8601String and DateUtils.FromISO8601TimeZone
            Console.WriteLine("Expressed in Universal Time");

            Console.WriteLine("20180314 = {0}", DateUtils.FromISO8601String("20180314", false));
            Console.WriteLine("20180314T10 = {0}", DateUtils.FromISO8601String("20180314T10", false));
            Console.WriteLine("20180314T1025 = {0}", DateUtils.FromISO8601String("20180314T1025", false));
            Console.WriteLine("20180314T102531 = {0}", DateUtils.FromISO8601String("20180314T102531", false));
            Console.WriteLine("20180314T102531.123 = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("20180314T102531.123", false));
            Console.WriteLine("20180314T102531.98Z = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("20180314T102531.98Z", false));
            Console.WriteLine("20180314T102531-04 = {0}", DateUtils.FromISO8601String("20180314T102531-04", false));
            Console.WriteLine("20180314T102531.123+0830 = {0}",
                              DateUtils.FromISO8601String("20180314T102531.123+0830", false));

            Console.WriteLine("\n2018-03-14 = {0}", DateUtils.FromISO8601String("2018-03-14", false));
            Console.WriteLine("2018-03-14T10 = {0}", DateUtils.FromISO8601String("2018-03-14T10", false));
            Console.WriteLine("2018-03-14T10:25 = {0}", DateUtils.FromISO8601String("2018-03-14T10:25", false));
            Console.WriteLine("2018-03-14T10:25:31 = {0}", DateUtils.FromISO8601String("2018-03-14T10:25:31", false));
            Console.WriteLine("2018-03-14T10:25:31.123 = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31.123", false));
            Console.WriteLine("2018-03-14T10:25:31.98Z = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31.98Z", false));
            Console.WriteLine("2018-03-14T10:25:31-04 = {0}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31-04", false));
            Console.WriteLine("2018-03-14T10:25:31+08:30 = {0}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31+08:30", false));

            // Test DateUtils.FromISO8601String and DateUtils.FromISO8601TimeZone
            Console.WriteLine("\nExpressed in Local Time");

            Console.WriteLine("20180314 = {0}", DateUtils.FromISO8601String("20180314", true));
            Console.WriteLine("20180314T10 = {0}", DateUtils.FromISO8601String("20180314T10", true));
            Console.WriteLine("20180314T1025 = {0}", DateUtils.FromISO8601String("20180314T1025", true));
            Console.WriteLine("20180314T102531 = {0}", DateUtils.FromISO8601String("20180314T102531", true));
            Console.WriteLine("20180314T102531.123 = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("20180314T102531.123", true));
            Console.WriteLine("20180314T102531.98Z = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("20180314T102531.98Z", true));
            Console.WriteLine("20180314T102531-04 = {0}", DateUtils.FromISO8601String("20180314T102531-04", true));
            Console.WriteLine("20180314T102531.123+0830 = {0}",
                              DateUtils.FromISO8601String("20180314T102531.123+0830", true));

            Console.WriteLine("\n2018-03-14 = {0}", DateUtils.FromISO8601String("2018-03-14", true));
            Console.WriteLine("2018-03-14T10 = {0}", DateUtils.FromISO8601String("2018-03-14T10", true));
            Console.WriteLine("2018-03-14T10:25 = {0}", DateUtils.FromISO8601String("2018-03-14T10:25", true));
            Console.WriteLine("2018-03-14T10:25:31 = {0}", DateUtils.FromISO8601String("2018-03-14T10:25:31", true));
            Console.WriteLine("2018-03-14T10:25:31.123 = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31.123", true));
            Console.WriteLine("2018-03-14T10:25:31.98Z = {0:d} {0:HH:mm:ss.fff}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31.98Z", true));
            Console.WriteLine("2018-03-14T10:25:31-04 = {0}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31-04", true));
            Console.WriteLine("2018-03-14T10:25:31+08:30 = {0}",
                              DateUtils.FromISO8601String("2018-03-14T10:25:31+08:30", true));

            TimeSpan ts = DateUtils.FromISO8601TimeZone("+08");

            Console.WriteLine("\n+08 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("-08");

            Console.WriteLine("-08 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("-0830");

            Console.WriteLine("-0830 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("+08:30");

            Console.WriteLine("+08:30 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            // Restrict bad date part values to their minimum/maximum
            Console.WriteLine("\nBad date values test");

            Console.WriteLine("0000-01-01T10:25:00 = {0}",
                              DateUtils.FromISO8601String("0000-01-01T10:25:00", true));
            Console.WriteLine("0000-00-01T10:25:00 = {0}",
                              DateUtils.FromISO8601String("0000-00-01T10:25:00", true));
            Console.WriteLine("0000-13-01T10:25:00 = {0}",
                              DateUtils.FromISO8601String("0000-13-01T10:25:00", true));
            Console.WriteLine("0000-00-00T10:25:00 = {0}",
                              DateUtils.FromISO8601String("0000-00-00T10:25:00", true));
            Console.WriteLine("0000-00-32T10:25:00 = {0}",
                              DateUtils.FromISO8601String("0000-00-32T10:25:00", true));

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test the Duration class
            Console.WriteLine("Assumptions: 1 year = {0} days, 1 month = {1} days\n", Duration.DaysInOneYear,
                              Duration.DaysInOneMonth);

            Duration d = new Duration("P1Y2M3W4DT5H6M7S");

            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0}", d.ToString());
            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToString(Duration.MaxUnit.Months));

            d = new Duration("P10Y11MT16M12S");

            Console.WriteLine("P10Y11MT16M12S = {0}", d.ToString());

            d = new Duration("P5M2DT16M");

            Console.WriteLine("P5M2DT16M = {0}", d.ToString());

            d = new Duration("P7W");

            Console.WriteLine("P7W = {0}", d.ToString());
            Console.WriteLine("P7W = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("P7W2D");

            Console.WriteLine("P7W2D = {0}", d.ToString());
            Console.WriteLine("P7W2D = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W2D = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("P5DT2S");

            Console.WriteLine("P5DT2S = {0}", d.ToString());

            d = new Duration("PT24H");

            Console.WriteLine("PT24H = {0}", d.ToString());
            Console.WriteLine("PT24H = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("PT24H3M2S");

            Console.WriteLine("PT24H3M2S = {0}", d.ToString());
            Console.WriteLine("PT24H3M2S = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H3M2S = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H3M2S = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("PT1H10M20S");

            Console.WriteLine("PT1H10M20S = {0}", d.ToString());

            d = new Duration("PT5M20S");

            Console.WriteLine("PT5M20S = {0}", d.ToString());

            d = new Duration("PT5S");

            Console.WriteLine("PT5S = {0}", d.ToString());

            d = new Duration("P0Y0M0W0DT0H0M0S");

            Console.WriteLine("P0Y0M0W0DT0H0M0S = {0}", d.ToString());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            d = new Duration("-P1Y2M3W4DT5H6M7S");

            Console.WriteLine("\n-P1Y2M3W4DT5H6M7S = {0}", d.ToString());
            Console.WriteLine("-P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToString(Duration.MaxUnit.Months));

            d = new Duration("-P10Y11MT16M12S");

            Console.WriteLine("-P10Y11MT16M12S = {0}", d.ToString());

            d = new Duration("-P5M2DT16M");

            Console.WriteLine("-P5M2DT16M = {0}", d.ToString());

            d = new Duration("-P7W");

            Console.WriteLine("-P7W = {0}", d.ToString());
            Console.WriteLine("-P7W = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("-P7W2D");

            Console.WriteLine("-P7W2D = {0}", d.ToString());
            Console.WriteLine("-P7W2D = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W2D = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("-P5DT2S");

            Console.WriteLine("-P5DT2S = {0}", d.ToString());

            d = new Duration("-PT24H");

            Console.WriteLine("-PT24H = {0}", d.ToString());
            Console.WriteLine("-PT24H = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("-PT24H3M2S");

            Console.WriteLine("-PT24H3M2S = {0}", d.ToString());
            Console.WriteLine("-PT24H3M2S = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H3M2S = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H3M2S = {0} (max units = seconds)", d.ToString(Duration.MaxUnit.Seconds));

            d = new Duration("-PT1H10M20S");

            Console.WriteLine("-PT1H10M20S = {0}", d.ToString());

            d = new Duration("-PT5M20S");

            Console.WriteLine("-PT5M20S = {0}", d.ToString());

            d = new Duration("-PT5S");

            Console.WriteLine("-PT5S = {0}", d.ToString());

            d = new Duration("-P0Y0M0W0DT0H0M0S");

            Console.WriteLine("-P0Y0M0W0DT0H0M0S = {0}", d.ToString());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test the ToDescription() methods
            d = new Duration("P1Y2M3W4DT5H6M7S");

            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0}", d.ToDescription());
            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToDescription(Duration.MaxUnit.Months));

            d = new Duration("P10Y11MT16M12S");

            Console.WriteLine("P10Y11MT16M12S = {0}", d.ToDescription());

            d = new Duration("P5M2DT16M");

            Console.WriteLine("P5M2DT16M = {0}", d.ToDescription());

            d = new Duration("P7W");

            Console.WriteLine("P7W = {0}", d.ToDescription());
            Console.WriteLine("P7W = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("P7W2D");

            Console.WriteLine("P7W2D = {0}", d.ToDescription());
            Console.WriteLine("P7W2D = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W2D = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("P5DT2S");

            Console.WriteLine("P5DT2S = {0}", d.ToDescription());

            d = new Duration("PT24H");

            Console.WriteLine("PT24H = {0}", d.ToDescription());
            Console.WriteLine("PT24H = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("PT24H3M2S");

            Console.WriteLine("PT24H3M2S = {0}", d.ToDescription());
            Console.WriteLine("PT24H3M2S = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H3M2S = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H3M2S = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("PT1H10M20S");

            Console.WriteLine("PT1H10M20S = {0}", d.ToDescription());

            d = new Duration("PT5M20S");

            Console.WriteLine("PT5M20S = {0}", d.ToDescription());

            d = new Duration("PT5S");

            Console.WriteLine("PT5S = {0}", d.ToDescription());

            d = new Duration("P0Y0M0W0DT0H0M0S");

            Console.WriteLine("P0Y0M0W0DT0H0M0S = {0}", d.ToDescription());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            d = new Duration("-P1Y2M3W4DT5H6M7S");

            Console.WriteLine("\n-P1Y2M3W4DT5H6M7S = {0}", d.ToDescription());
            Console.WriteLine("-P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToDescription(Duration.MaxUnit.Months));

            d = new Duration("-P10Y11MT16M12S");

            Console.WriteLine("-P10Y11MT16M12S = {0}", d.ToDescription());

            d = new Duration("-P5M2DT16M");

            Console.WriteLine("-P5M2DT16M = {0}", d.ToDescription());

            d = new Duration("-P7W");

            Console.WriteLine("-P7W = {0}", d.ToDescription());
            Console.WriteLine("-P7W = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("-P7W2D");

            Console.WriteLine("-P7W2D = {0}", d.ToDescription());
            Console.WriteLine("-P7W2D = {0} (max units = weeks)", d.ToDescription(Duration.MaxUnit.Weeks));
            Console.WriteLine("-P7W2D = {0} (max units = days)", d.ToDescription(Duration.MaxUnit.Days));

            d = new Duration("-P5DT2S");

            Console.WriteLine("-P5DT2S = {0}", d.ToDescription());

            d = new Duration("-PT24H");

            Console.WriteLine("-PT24H = {0}", d.ToDescription());
            Console.WriteLine("-PT24H = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("-PT24H3M2S");

            Console.WriteLine("-PT24H3M2S = {0}", d.ToDescription());
            Console.WriteLine("-PT24H3M2S = {0} (max units = hours)", d.ToDescription(Duration.MaxUnit.Hours));
            Console.WriteLine("-PT24H3M2S = {0} (max units = minutes)", d.ToDescription(Duration.MaxUnit.Minutes));
            Console.WriteLine("-PT24H3M2S = {0} (max units = seconds)", d.ToDescription(Duration.MaxUnit.Seconds));

            d = new Duration("-PT1H10M20S");

            Console.WriteLine("-PT1H10M20S = {0}", d.ToDescription());

            d = new Duration("-PT5M20S");

            Console.WriteLine("-PT5M20S = {0}", d.ToDescription());

            d = new Duration("-PT5S");

            Console.WriteLine("-PT5S = {0}", d.ToDescription());

            d = new Duration("-P0Y0M0W0DT0H0M0S");

            Console.WriteLine("-P0Y0M0W0DT0H0M0S = {0}", d.ToDescription());

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Create a set of fixed and floating holidays
            HolidayCollection holidays = new HolidayCollection();

            holidays.AddFixed(1, 1, true, "New Year's Day");
            holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 1, 0, "Martin Luther King Day");
            holidays.AddFloating(DayOccurrence.Third, DayOfWeek.Monday, 2, 0, "President's Day");
            holidays.AddFloating(DayOccurrence.Last, DayOfWeek.Monday, 5, 0, "Memorial Day");
            holidays.AddFixed(7, 4, true, "Independence Day");
            holidays.AddFloating(DayOccurrence.First, DayOfWeek.Monday, 9, 0, "Labor Day");
            holidays.AddFixed(11, 11, true, "Veteran's Day");
            holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 0, "Thanksgiving Day");
            holidays.AddFloating(DayOccurrence.Fourth, DayOfWeek.Thursday, 11, 1, "Day After Thanksgiving");
            holidays.AddFixed(12, 25, true, "Christmas Day");

            // Serialize the holidays to a file
            try
            {
                // XML
                using (var fs = new FileStream("Holidays.xml", FileMode.Create))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(HolidayCollection));
                    xs.Serialize(fs, holidays);

                    Console.WriteLine("Holidays saved to Holidays.xml");
                }
#if NETFramework
                // The SOAP formatter is only supported on the full .NET Framework
                // SOAP
                using (var fs = new FileStream("Holidays.soap", FileMode.Create))
                {
                    var sf = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();

                    // SOAP doesn't support generics directly so use an array
                    sf.Serialize(fs, holidays.ToArray());

                    Console.WriteLine("Holidays saved to Holidays.soap");
                }
#endif
                // Binary
                using (var fs = new FileStream("Holidays.bin", FileMode.Create))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, holidays);

                    Console.WriteLine("Holidays saved to Holidays.bin\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to save holidays:\n{0}", ex.Message);

                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if (ex.InnerException.InnerException != null)
                    {
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                    }
                }
            }

            // Delete the collection and read it back in
            holidays = null;

            try
            {
                // XML
                using (var fs = new FileStream("Holidays.xml", FileMode.Open))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(HolidayCollection));
                    holidays = (HolidayCollection)xs.Deserialize(fs);

                    Console.WriteLine("Holidays retrieved from Holidays.xml");
                }
#if NETFramework
                // SOAP
                using (var fs = new FileStream("Holidays.soap", FileMode.Open))
                {
                    var sf = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();

                    // As noted, SOAP doesn't support generics to an array is used instead
                    holidays = new HolidayCollection((Holiday[])sf.Deserialize(fs));

                    Console.WriteLine("Holidays retrieved from Holidays.soap");
                }
#endif
                // Binary
                using (var fs = new FileStream("Holidays.bin", FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    holidays = (HolidayCollection)bf.Deserialize(fs);

                    Console.WriteLine("Holidays retrieved from Holidays.bin\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to load holidays:\n{0}", ex.Message);

                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if (ex.InnerException.InnerException != null)
                    {
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                    }
                }
            }

            // Display the holidays added to the list
            Console.WriteLine("Holidays on file.  Is Holiday should be true for all.");

            foreach (Holiday hol in holidays)
            {
                Console.WriteLine("Holiday Date: {0:d}   Is Holiday: {1}  Description: {2}",
                                  hol.ToDateTime(yearFrom), holidays.IsHoliday(hol.ToDateTime(yearFrom)), hol.Description);
            }

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Display holidays found in each year specified using the IsHoliday method
            Console.WriteLine("Looking for holidays using the IsHoliday method");

            testDate = new DateTime(yearFrom, 1, 1);

            while (testDate.Year <= yearTo)
            {
                if (holidays.IsHoliday(testDate))
                {
                    Console.WriteLine("Found holiday: {0:d} {1}", testDate, holidays.HolidayDescription(testDate));
                }

                testDate = testDate.AddDays(1);

                // Stop after each year to review output
                if (testDate.Month == 1 && testDate.Day == 1)
                {
                    Console.WriteLine("Press ENTER to continue");
                    Console.ReadLine();
                }
            }

            // One more time, but use a hash set using the dates returned by the HolidaysBetween() method.  For
            // bulk comparisons, this is faster than the above procedure using the IsHoliday method.
            Console.WriteLine("Looking for holidays using HolidaysBetween");

            holidayDates = new HashSet <DateTime>(holidays.HolidaysBetween(yearFrom, yearTo));

            if (holidayDates.Count != 0)
            {
                testDate = new DateTime(yearFrom, 1, 1);

                while (testDate.Year <= yearTo)
                {
                    if (holidayDates.Contains(testDate))
                    {
                        Console.WriteLine("Found holiday: {0:d} {1}", testDate, holidays.HolidayDescription(testDate));
                    }

                    testDate = testDate.AddDays(1);

                    // Stop after each year to review output
                    if (testDate.Month == 1 && testDate.Day == 1)
                    {
                        Console.WriteLine("Press ENTER to continue");
                        Console.ReadLine();
                    }
                }
            }

            //=================================================================

            // Test recurrence
            Recurrence rRecur = new Recurrence();
            Recurrence.Holidays.AddRange(holidays);

            // Disallow occurrences on any of the defined holidays
            rRecur.CanOccurOnHoliday = false;

            testDate = new DateTime(yearFrom, 1, 1);

            // Test daily recurrence
            rRecur.StartDateTime = testDate;
            rRecur.RecurUntil    = testDate.AddMonths(1); // For the enumerator
            rRecur.RecurDaily(2);

            // Serialize the recurrence to a file
            try
            {
                // XML
                using (var fs = new FileStream("Recurrence.xml", FileMode.Create))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Recurrence));
                    xs.Serialize(fs, rRecur);

                    Console.WriteLine("Recurrence saved to Recurrence.xml");
                }
#if NETFramework
                // SOAP
                using (var fs = new FileStream("Recurrence.soap", FileMode.Create))
                {
                    var sf = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
                    sf.Serialize(fs, rRecur);

                    Console.WriteLine("Recurrence saved to Recurrence.soap");
                }
#endif
                // Binary
                using (var fs = new FileStream("Recurrence.bin", FileMode.Create))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, rRecur);

                    Console.WriteLine("Recurrence saved to Recurrence.bin\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to save recurrence:\n{0}", ex.Message);

                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if (ex.InnerException.InnerException != null)
                    {
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                    }
                }
            }

            // Deserialize the recurrence from a file
            rRecur = null;

            try
            {
                // XML
                using (var fs = new FileStream("Recurrence.xml", FileMode.Open))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Recurrence));
                    rRecur = (Recurrence)xs.Deserialize(fs);

                    Console.WriteLine("Recurrence restored from Recurrence.xml");
                }
#if NETFramework
                // SOAP
                using (var fs = new FileStream("Recurrence.soap", FileMode.Open))
                {
                    var sf = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
                    rRecur = (Recurrence)sf.Deserialize(fs);

                    Console.WriteLine("Recurrence retrieved from Recurrence.soap");
                }
#endif
                // Binary
                using (var fs = new FileStream("Recurrence.bin", FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    rRecur = (Recurrence)bf.Deserialize(fs);

                    Console.WriteLine("Recurrence retrieved from Recurrence.bin\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to restore recurrence:\n{0}", ex.Message);

                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    if (ex.InnerException.InnerException != null)
                    {
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                    }
                }
            }

            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(1));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Daily recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Daily recurrence on: {0:d}", dt);
            }

            // Test NextInstance().  This isn't the most efficient way of searching for lots of dates but is
            // useful for one-off searches.
            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Daily recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test weekly recurrence
            rRecur.StartDateTime = testDate;
            rRecur.RecurWeekly(1, DaysOfWeek.Monday | DaysOfWeek.Wednesday);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(1));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Weekly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Weekly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Weekly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test monthly recurrence (option 1)
            rRecur.StartDateTime = testDate;
            rRecur.RecurUntil    = testDate.AddMonths(12); // For the enumerator
            rRecur.RecurMonthly(15, 2);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(12));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Monthly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Monthly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Monthly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test monthly recurrence (option 2)
            rRecur.RecurMonthly(DayOccurrence.Third, DaysOfWeek.Thursday, 3);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(12));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Monthly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Monthly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Monthly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test monthly recurrence (option 3 - a variation of option 2)
            rRecur.RecurMonthly(DayOccurrence.Third, DaysOfWeek.Weekends, 2);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddMonths(12));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Monthly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Monthly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Monthly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test yearly recurrence (option 1)
            rRecur.StartDateTime = testDate;
            rRecur.RecurUntil    = testDate.AddYears(5); // For the enumerator
            rRecur.RecurYearly(5, 24, 1);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddYears(5));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Yearly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Yearly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Yearly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test yearly recurrence (option 2)
            rRecur.RecurYearly(DayOccurrence.Last, DaysOfWeek.Sunday, 9, 2);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddYears(5));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Yearly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Yearly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Yearly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test yearly recurrence (option 3 - a variation of option 2)
            rRecur.RecurYearly(DayOccurrence.Last, DaysOfWeek.Weekdays, 7, 1);
            recurDates = rRecur.InstancesBetween(testDate, testDate.AddYears(5));

            Console.WriteLine(rRecur.ToStringWithStartDateTime());

            foreach (DateTime dt in recurDates)
            {
                Console.WriteLine("(Collection) Yearly recurrence on: {0:d}", dt);
            }

            foreach (DateTime dt in rRecur)
            {
                Console.WriteLine("(Enumerator) Yearly recurrence on: {0:d}", dt);
            }

            nextDate = testDate;

            do
            {
                nextDate = rRecur.NextInstance(nextDate, false);

                if (nextDate != DateTime.MinValue)
                {
                    Console.WriteLine("(NextInstance) Yearly recurrence on: {0:d}", nextDate);
                    nextDate = nextDate.AddMinutes(1);
                }
            } while(nextDate != DateTime.MinValue);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();
        }
 public void ClearAllHolidays()
 {
     HolidayCollection.Clear();
     Assert.AreEqual(HolidayCollection.Count(), 0);
 }
 public void CanAddNewDatetime()
 {
     HolidayCollection.Clear();
     HolidayCollection.Add(DateTime.Now);
     Assert.Greater(HolidayCollection.Count(), 0);
 }
Exemplo n.º 26
0
        private void getAllHolidays()
        {
            HolidayCollection myHolidayCollection = new HolidayCollection();

            myHolidayCollection.RetreiveAllHolidays();
        }
Exemplo n.º 27
0
 public void AddDaysWithHolidays()
 {
     HolidayCollection.Add(new DateTime(2015, 7, 23));
     Assert.AreEqual(new DateTime(2015, 7, 24), date.AddWorkableDays(3));
     HolidayCollection.Clear();
 }