Exemplo n.º 1
0
        public void Monthly_EveryMonth_Ordinal_LastWeek()
        {
            // Arrange.
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2018, 1, 1)) // Monday
                                 .Every(1)
                                 .Months()
                                 .OnOrdinalWeek(Ordinal.LAST)
                                 .OnDay(DayOfWeek.Wednesday)
                                 .Ending(new DateTime(2018, 12, 25))
                                 .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2018, 1, 31), monthly.Next(new DateTime(2017, 1, 1)));
            Assert.Equal(new DateTime(2018, 1, 31), monthly.Next(new DateTime(2018, 1, 1)));
            Assert.Equal(new DateTime(2018, 1, 31), monthly.Next(new DateTime(2018, 1, 31)));
            Assert.Equal(new DateTime(2018, 2, 28), monthly.Next(new DateTime(2018, 2, 1)));
            Assert.Equal(new DateTime(2018, 4, 25), monthly.Next(new DateTime(2018, 4, 1)));

            Assert.Null(monthly.Next(new DateTime(2020, 2, 1)));

            Assert.Equal(new DateTime(2018, 1, 31), monthly.Previous(new DateTime(2018, 2, 1)));
            Assert.Equal(new DateTime(2018, 1, 31), monthly.Previous(new DateTime(2018, 2, 28)));
            Assert.Equal(new DateTime(2018, 2, 28), monthly.Previous(new DateTime(2018, 3, 1)));
            Assert.Equal(new DateTime(2018, 3, 28), monthly.Previous(new DateTime(2018, 4, 25)));
            Assert.Equal(new DateTime(2018, 4, 25), monthly.Previous(new DateTime(2018, 4, 26)));

            Assert.Null(monthly.Previous(new DateTime(2018, 1, 31)));
        }
Exemplo n.º 2
0
        public void Daily_EveryDay()
        {
            // Arrange.
            IRecurring daily = Recurs
                               .Starting(new DateTime(2015, 1, 1))
                               .Every(1)
                               .Days()
                               .Ending(new DateTime(2015, 1, 15))
                               .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 1), daily.Next(new DateTime(2014, 7, 3)));
            Assert.Equal(new DateTime(2015, 1, 2), daily.Next(new DateTime(2015, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 3), daily.Next(new DateTime(2015, 1, 2)));

            Assert.Null(daily.Next(new DateTime(2015, 1, 15)));

            Assert.Equal(new DateTime(2015, 1, 1), daily.Previous(new DateTime(2015, 1, 2)));
            Assert.Equal(new DateTime(2015, 1, 2), daily.Previous(new DateTime(2015, 1, 3)));
            Assert.Equal(new DateTime(2015, 1, 3), daily.Previous(new DateTime(2015, 1, 4)));
            Assert.Equal(new DateTime(2015, 1, 14), daily.Previous(new DateTime(2015, 1, 15)));
            Assert.Equal(new DateTime(2015, 1, 15), daily.Previous(new DateTime(2015, 1, 16)));
            Assert.Equal(new DateTime(2015, 1, 15), daily.Previous(new DateTime(2015, 1, 17)));

            Assert.Null(daily.Previous(new DateTime(2015, 1, 1)));
        }
Exemplo n.º 3
0
        public void Monthly_EveryThirdMonth_Ordinal()
        {
            // Arrange.
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2018, 1, 1)) // Monday
                                 .Every(3)
                                 .Months()
                                 .OnOrdinalWeek(Ordinal.SECOND)
                                 .OnDay(DayOfWeek.Friday)
                                 .Ending(new DateTime(2018, 12, 25))
                                 .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2018, 1, 12), monthly.Next(new DateTime(2017, 1, 1)));
            Assert.Equal(new DateTime(2018, 1, 12), monthly.Next(new DateTime(2018, 1, 1)));
            Assert.Equal(new DateTime(2018, 1, 12), monthly.Next(new DateTime(2018, 1, 12)));
            Assert.Equal(new DateTime(2018, 7, 13), monthly.Next(new DateTime(2018, 7, 1)));

            Assert.Null(monthly.Next(new DateTime(2020, 2, 1)));

            Assert.Equal(new DateTime(2018, 1, 12), monthly.Previous(new DateTime(2018, 1, 13)));
            Assert.Equal(new DateTime(2018, 1, 12), monthly.Previous(new DateTime(2018, 4, 13)));
            Assert.Equal(new DateTime(2018, 4, 13), monthly.Previous(new DateTime(2018, 4, 14)));
            Assert.Equal(new DateTime(2018, 4, 13), monthly.Previous(new DateTime(2018, 7, 13)));

            Assert.Null(monthly.Previous(new DateTime(2018, 1, 12)));
        }
        public void Yearly_EveryThirdYear_Ordinal()
        {
            // Arrange.
            var startDate = new DateTime(2018, 1, 1);

            IRecurring yearly = Recurs
                                .Starting(startDate)
                                .Every(3)
                                .Years()
                                .OnOrdinalWeek(Ordinal.THIRD)
                                .OnDay(DayOfWeek.Thursday)
                                .OnMonths(Month.JANUARY)
                                .Ending(new DateTime(2030, 1, 1))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2018, 1, 18), yearly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2018, 1, 18), yearly.Next(new DateTime(2018, 1, 1)));
            Assert.Equal(new DateTime(2021, 1, 21), yearly.Next(new DateTime(2018, 1, 18)));
            Assert.Equal(new DateTime(2024, 1, 18), yearly.Next(new DateTime(2021, 2, 18)));

            Assert.Null(yearly.Next(new DateTime(2030, 1, 1)));

            Assert.Equal(new DateTime(2018, 1, 18), yearly.Previous(new DateTime(2018, 1, 19)));
            Assert.Equal(new DateTime(2018, 1, 18), yearly.Previous(new DateTime(2021, 1, 21)));
            Assert.Equal(new DateTime(2021, 1, 21), yearly.Previous(new DateTime(2021, 1, 22)));
            Assert.Equal(new DateTime(2024, 1, 18), yearly.Previous(new DateTime(2024, 1, 19)));

            Assert.Null(yearly.Previous(new DateTime(2018, 1, 18)));
        }
        public void Yearly_MultipleMonths_Ordinal()
        {
            // Arrange.
            var startDate = new DateTime(2018, 1, 1);

            IRecurring yearly = Recurs
                                .Starting(startDate)
                                .Every(1)
                                .Years()
                                .OnOrdinalWeek(Ordinal.THIRD)
                                .OnDay(DayOfWeek.Thursday)
                                .OnMonths(Month.JANUARY | Month.APRIL)
                                .Ending(new DateTime(2030, 1, 1))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2018, 1, 18), yearly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2018, 1, 18), yearly.Next(new DateTime(2018, 1, 1)));
            Assert.Equal(new DateTime(2018, 4, 19), yearly.Next(new DateTime(2018, 1, 18)));
            Assert.Equal(new DateTime(2019, 1, 17), yearly.Next(new DateTime(2018, 4, 19)));

            Assert.Null(yearly.Next(new DateTime(2030, 1, 1)));

            Assert.Equal(new DateTime(2018, 1, 18), yearly.Previous(new DateTime(2018, 1, 19)));
            Assert.Equal(new DateTime(2018, 1, 18), yearly.Previous(new DateTime(2018, 4, 19)));
            Assert.Equal(new DateTime(2018, 4, 19), yearly.Previous(new DateTime(2018, 4, 20)));
            Assert.Equal(new DateTime(2019, 1, 17), yearly.Previous(new DateTime(2019, 1, 18)));

            Assert.Null(yearly.Previous(new DateTime(2018, 1, 18)));
        }
        public void Yearly_EveryYear_DifferentDaysInMonth()
        {
            // Arrange.
            IRecurring yearly = Recurs
                                .Starting(new DateTime(2015, 1, 1))
                                .Every(1)
                                .Years()
                                .OnDay(31)
                                .OnMonths(Month.JANUARY | Month.FEBRUARY | Month.AUGUST)
                                .Ending(new DateTime(2020, 1, 1))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 31), yearly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 31), yearly.Next(new DateTime(2015, 1, 6)));
            Assert.Equal(new DateTime(2015, 2, 28), yearly.Next(new DateTime(2015, 1, 31)));
            Assert.Equal(new DateTime(2015, 2, 28), yearly.Next(new DateTime(2015, 2, 27)));
            Assert.Equal(new DateTime(2015, 8, 31), yearly.Next(new DateTime(2015, 2, 28)));

            Assert.Null(yearly.Next(new DateTime(2020, 1, 1)));

            Assert.Equal(new DateTime(2015, 1, 31), yearly.Previous(new DateTime(2015, 2, 1)));
            Assert.Equal(new DateTime(2015, 1, 31), yearly.Previous(new DateTime(2015, 2, 28)));
            Assert.Equal(new DateTime(2015, 2, 28), yearly.Previous(new DateTime(2015, 3, 1)));
            Assert.Equal(new DateTime(2015, 2, 28), yearly.Previous(new DateTime(2015, 3, 1)));
            Assert.Equal(new DateTime(2015, 8, 31), yearly.Previous(new DateTime(2015, 9, 1)));

            Assert.Null(yearly.Previous(new DateTime(2015, 1, 31)));
        }
        public void Weekly_Every2Weeks_SatSun()
        {
            // Arrange.
            DateTime startDate = new DateTime(2018, 2, 22);

            IRecurring weekly = Recurs
                                .Starting(startDate)
                                .Every(2)
                                .Weeks()
                                .FirstDayOfWeek(DayOfWeek.Monday)
                                .OnDays(Day.SATURDAY | Day.SUNDAY)
                                .Ending(new DateTime(2018, 8, 28))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2018, 2, 24), weekly.Next(new DateTime(2018, 2, 23)));
            Assert.Equal(new DateTime(2018, 2, 25), weekly.Next(new DateTime(2018, 2, 24)));

            Assert.Equal(new DateTime(2018, 3, 10), weekly.Next(new DateTime(2018, 3, 2)));
            Assert.Equal(new DateTime(2018, 3, 10), weekly.Next(new DateTime(2018, 3, 3)));

            Assert.Equal(new DateTime(2018, 3, 10), weekly.Next(new DateTime(2018, 3, 9)));
            Assert.Equal(new DateTime(2018, 3, 11), weekly.Next(new DateTime(2018, 3, 10)));

            Assert.Null(weekly.Next(new DateTime(2018, 8, 28)));
        }
Exemplo n.º 8
0
        public void Yearly_EveryYear_TwoMonthsAfterDateTime()
        {
            // Arrange.
            var startDate = new DateTime(2015, 1, 1);

            IRecurring yearly = Recurs
                                .Starting(startDate)
                                .Every(1)
                                .Years()
                                .OnDay(24)
                                .OnMonth(startDate.AddMonths(2))
                                .Ending(new DateTime(2020, 1, 1))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 3, 24), yearly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 3, 24), yearly.Next(new DateTime(2015, 1, 1)));
            Assert.Equal(new DateTime(2015, 3, 24), yearly.Next(new DateTime(2015, 1, 23)));
            Assert.Equal(new DateTime(2016, 3, 24), yearly.Next(new DateTime(2015, 3, 24)));
            Assert.Equal(new DateTime(2016, 3, 24), yearly.Next(new DateTime(2015, 3, 25)));
            Assert.Equal(new DateTime(2016, 3, 24), yearly.Next(new DateTime(2015, 10, 1)));
            Assert.Equal(new DateTime(2016, 3, 24), yearly.Next(new DateTime(2015, 10, 23)));
            Assert.Equal(new DateTime(2016, 3, 24), yearly.Next(new DateTime(2015, 10, 24)));
            Assert.Equal(new DateTime(2017, 3, 24), yearly.Next(new DateTime(2016, 3, 24)));
            Assert.Equal(new DateTime(2017, 3, 24), yearly.Next(new DateTime(2016, 4, 24)));
            Assert.Null(yearly.Next(new DateTime(2020, 1, 1)));
        }
Exemplo n.º 9
0
        public void Weekly_EveryWeek_TwoDaysAfterDateTime()
        {
            // Arrange.
            DateTime startDate = new DateTime(2015, 1, 1);

            IRecurring weekly = Recurs
                                .Starting(startDate)
                                .Every(1)
                                .Weeks()
                                .OnDay(DayOfWeek.Saturday)
                                .Ending(new DateTime(2015, 2, 19))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 3), weekly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 3), weekly.Next(new DateTime(2015, 1, 2)));
            Assert.Equal(new DateTime(2015, 1, 10), weekly.Next(new DateTime(2015, 1, 6)));
            Assert.Equal(new DateTime(2015, 1, 10), weekly.Next(new DateTime(2015, 1, 9)));
            Assert.Equal(new DateTime(2015, 1, 17), weekly.Next(new DateTime(2015, 1, 13)));

            Assert.Null(weekly.Next(new DateTime(2015, 2, 19)));

            Assert.Equal(new DateTime(2015, 1, 3), weekly.Previous(new DateTime(2015, 1, 4)));
            Assert.Equal(new DateTime(2015, 1, 3), weekly.Previous(new DateTime(2015, 1, 10)));
            Assert.Equal(new DateTime(2015, 1, 10), weekly.Previous(new DateTime(2015, 1, 11)));
            Assert.Equal(new DateTime(2015, 1, 10), weekly.Previous(new DateTime(2015, 1, 17)));
            Assert.Equal(new DateTime(2015, 1, 17), weekly.Previous(new DateTime(2015, 1, 18)));

            Assert.Null(weekly.Previous(new DateTime(2015, 1, 3)));
        }
Exemplo n.º 10
0
        public void Weekly_EveryThirdWeek()
        {
            // Arrange.
            IRecurring weekly = Recurs
                                .Starting(new DateTime(2015, 1, 1))
                                .Every(3)
                                .Weeks()
                                .OnDays(Day.TUESDAY | Day.FRIDAY)
                                .Ending(new DateTime(2015, 2, 19))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 2), weekly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 20), weekly.Next(new DateTime(2015, 1, 2)));
            Assert.Equal(new DateTime(2015, 1, 23), weekly.Next(new DateTime(2015, 1, 21)));
            Assert.Equal(new DateTime(2015, 2, 10), weekly.Next(new DateTime(2015, 1, 23)));
            Assert.Equal(new DateTime(2015, 2, 10), weekly.Next(new DateTime(2015, 1, 24)));
            Assert.Equal(new DateTime(2015, 2, 10), weekly.Next(new DateTime(2015, 1, 27)));
            Assert.Equal(new DateTime(2015, 2, 13), weekly.Next(new DateTime(2015, 2, 10)));

            Assert.Equal(new DateTime(2015, 1, 2), weekly.Previous(new DateTime(2015, 1, 3)));
            Assert.Equal(new DateTime(2015, 1, 20), weekly.Previous(new DateTime(2015, 1, 21)));
            Assert.Equal(new DateTime(2015, 1, 23), weekly.Previous(new DateTime(2015, 1, 24)));
            Assert.Equal(new DateTime(2015, 2, 10), weekly.Previous(new DateTime(2015, 2, 11)));
            Assert.Equal(new DateTime(2015, 2, 10), weekly.Previous(new DateTime(2015, 2, 13)));
            Assert.Equal(new DateTime(2015, 2, 13), weekly.Previous(new DateTime(2015, 2, 14)));
        }
Exemplo n.º 11
0
        public void Yearly_EveryYear()
        {
            // Arrange.
            IRecurring yearly = Recurs
                                .Starting(new DateTime(2015, 1, 1))
                                .Every(1)
                                .Years()
                                .OnDay(24)
                                .OnMonths(Month.JANUARY | Month.FEBRUARY | Month.AUGUST)
                                .Ending(new DateTime(2020, 1, 1))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 24), yearly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 24), yearly.Next(new DateTime(2015, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 24), yearly.Next(new DateTime(2015, 1, 23)));
            Assert.Equal(new DateTime(2015, 2, 24), yearly.Next(new DateTime(2015, 1, 24)));
            Assert.Equal(new DateTime(2015, 2, 24), yearly.Next(new DateTime(2015, 1, 25)));
            Assert.Equal(new DateTime(2015, 2, 24), yearly.Next(new DateTime(2015, 2, 1)));
            Assert.Equal(new DateTime(2015, 2, 24), yearly.Next(new DateTime(2015, 2, 23)));
            Assert.Equal(new DateTime(2015, 8, 24), yearly.Next(new DateTime(2015, 2, 24)));
            Assert.Equal(new DateTime(2015, 8, 24), yearly.Next(new DateTime(2015, 3, 24)));
            Assert.Equal(new DateTime(2015, 8, 24), yearly.Next(new DateTime(2015, 4, 24)));
            Assert.Equal(new DateTime(2015, 8, 24), yearly.Next(new DateTime(2015, 5, 24)));
            Assert.Equal(new DateTime(2015, 8, 24), yearly.Next(new DateTime(2015, 6, 24)));
            Assert.Equal(new DateTime(2015, 8, 24), yearly.Next(new DateTime(2015, 7, 24)));
            Assert.Equal(new DateTime(2016, 1, 24), yearly.Next(new DateTime(2015, 8, 24)));
            Assert.Equal(new DateTime(2016, 2, 24), yearly.Next(new DateTime(2016, 1, 24)));
            Assert.Null(yearly.Next(new DateTime(2020, 1, 1)));
        }
Exemplo n.º 12
0
        public void Weekly_EveryWeek()
        {
            // Arrange.
            IRecurring weekly = Recurs
                                .Starting(new DateTime(2015, 1, 1)) // Thursday
                                .Every(1)
                                .Weeks()
                                .OnDays(Day.TUESDAY | Day.FRIDAY)
                                .Ending(new DateTime(2015, 1, 19)) // Thursday
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 2), weekly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 6), weekly.Next(new DateTime(2015, 1, 2)));
            Assert.Equal(new DateTime(2015, 1, 9), weekly.Next(new DateTime(2015, 1, 6)));
            Assert.Equal(new DateTime(2015, 1, 13), weekly.Next(new DateTime(2015, 1, 9)));
            Assert.Equal(new DateTime(2015, 1, 16), weekly.Next(new DateTime(2015, 1, 13)));

            Assert.Null(weekly.Next(new DateTime(2015, 1, 16)));

            Assert.Equal(new DateTime(2015, 1, 2), weekly.Previous(new DateTime(2015, 1, 6)));
            Assert.Equal(new DateTime(2015, 1, 6), weekly.Previous(new DateTime(2015, 1, 9)));
            Assert.Equal(new DateTime(2015, 1, 9), weekly.Previous(new DateTime(2015, 1, 13)));
            Assert.Equal(new DateTime(2015, 1, 13), weekly.Previous(new DateTime(2015, 1, 16)));
            Assert.Equal(new DateTime(2015, 1, 16), weekly.Previous(new DateTime(2015, 1, 19)));
            Assert.Equal(new DateTime(2015, 1, 16), weekly.Previous(new DateTime(2015, 1, 20)));
            Assert.Equal(new DateTime(2015, 1, 16), weekly.Previous(new DateTime(2015, 1, 21)));

            Assert.Null(weekly.Previous(new DateTime(2015, 1, 2)));
            Assert.Null(weekly.Previous(new DateTime(2015, 1, 1)));
            Assert.Null(weekly.Previous(new DateTime(2014, 1, 1)));
        }
Exemplo n.º 13
0
        public void Monthly_EveryMonth()
        {
            // Arrange.
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2015, 1, 1))
                                 .Every(1)
                                 .Months()
                                 .OnDay(24)
                                 .Ending(new DateTime(2016, 2, 4))
                                 .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 24), monthly.Next(new DateTime(2014, 4, 8)));
            Assert.Equal(new DateTime(2015, 2, 24), monthly.Next(new DateTime(2015, 1, 24)));
            Assert.Equal(new DateTime(2015, 2, 24), monthly.Next(new DateTime(2015, 2, 23)));
            Assert.Equal(new DateTime(2015, 3, 24), monthly.Next(new DateTime(2015, 2, 24)));
            Assert.Equal(new DateTime(2015, 3, 24), monthly.Next(new DateTime(2015, 2, 25)));
            Assert.Equal(new DateTime(2015, 6, 24), monthly.Next(new DateTime(2015, 6, 3)));

            Assert.Null(monthly.Next(new DateTime(2016, 6, 3)));

            Assert.Equal(new DateTime(2015, 1, 24), monthly.Previous(new DateTime(2015, 1, 25)));
            Assert.Equal(new DateTime(2015, 1, 24), monthly.Previous(new DateTime(2015, 2, 24)));
            Assert.Equal(new DateTime(2015, 2, 24), monthly.Previous(new DateTime(2015, 2, 25)));
            Assert.Equal(new DateTime(2015, 2, 24), monthly.Previous(new DateTime(2015, 3, 24)));
            Assert.Equal(new DateTime(2015, 2, 24), monthly.Previous(new DateTime(2015, 2, 25)));
            Assert.Equal(new DateTime(2015, 3, 24), monthly.Previous(new DateTime(2015, 3, 25)));
            Assert.Equal(new DateTime(2015, 3, 24), monthly.Previous(new DateTime(2015, 4, 24)));
            Assert.Equal(new DateTime(2015, 6, 24), monthly.Previous(new DateTime(2015, 6, 25)));

            Assert.Null(monthly.Previous(new DateTime(2015, 1, 24)));
        }
Exemplo n.º 14
0
        public void Monthly_EveryMonth_DifferentDaysInMonths()
        {
            // Arrange.
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2015, 1, 1))
                                 .Every(1)
                                 .Months()
                                 .OnDay(31)
                                 .Ending(new DateTime(2016, 2, 4))
                                 .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 31), monthly.Next(new DateTime(2014, 2, 1)));
            Assert.Equal(new DateTime(2015, 1, 31), monthly.Next(new DateTime(2015, 1, 30)));
            Assert.Equal(new DateTime(2015, 2, 28), monthly.Next(new DateTime(2015, 1, 31)));
            Assert.Equal(new DateTime(2015, 2, 28), monthly.Next(new DateTime(2015, 2, 27)));
            Assert.Equal(new DateTime(2015, 3, 31), monthly.Next(new DateTime(2015, 2, 28)));
            Assert.Equal(new DateTime(2015, 4, 30), monthly.Next(new DateTime(2015, 3, 31)));

            Assert.Null(monthly.Next(new DateTime(2016, 6, 3)));

            Assert.Equal(new DateTime(2015, 1, 31), monthly.Previous(new DateTime(2015, 2, 28)));
            Assert.Equal(new DateTime(2015, 1, 31), monthly.Previous(new DateTime(2015, 2, 1)));
            Assert.Equal(new DateTime(2015, 2, 28), monthly.Previous(new DateTime(2015, 3, 1)));
            Assert.Equal(new DateTime(2015, 2, 28), monthly.Previous(new DateTime(2015, 3, 15)));
            Assert.Equal(new DateTime(2015, 3, 31), monthly.Previous(new DateTime(2015, 4, 1)));
            Assert.Equal(new DateTime(2015, 4, 30), monthly.Previous(new DateTime(2015, 5, 1)));

            Assert.Null(monthly.Previous(new DateTime(2015, 1, 31)));
        }
Exemplo n.º 15
0
 protected Message(SerializationInfo info, StreamingContext context)
 {
     this.Text = info.GetString("subj");
     this.SubItems.Add(info.GetString("msgtxt"));
     this.SubItems.Add(info.GetString("recur"));
     this.SubItems.Add(info.GetString("senddate"));
     m_enRecurFrequency = (Recurs)info.GetInt32("ri");
     m_nLeadTime = info.GetInt32("lti");
     m_Date = info.GetDateTime("msgdate");
 }
Exemplo n.º 16
0
        public Message(String strSubj, String strMsgTxt, int nRecurIndex, String strRecur,
			int nLeadTimeIndex, DateTime date)
            : base(strSubj)
        {
            m_enRecurFrequency = (Recurs)nRecurIndex;
            m_nLeadTime = nLeadTimeIndex;
            m_Date = date;
            this.SubItems.Add(strMsgTxt);
            this.SubItems.Add(strRecur);
            this.SubItems.Add(this.SendDate.ToString("MMM d",DateTimeFormatInfo.InvariantInfo));
        }
Exemplo n.º 17
0
        public static bool RecursOnDate(this ChoreDefinition chore, DateTime checkDate)
        {
            // if chore not active then should not be valid
            if (chore.Active == false)
            {
                return(false);
            }

            // if non recurring task, is it for today
            if (chore.IsRepeating == false)
            {
                return(chore.StartDateTime.Date == checkDate.Date);
            }

            if (chore.RepeatingUnit == RepeatingUnitType.Day)
            {
                var daily = Recurs.Starting(chore.StartDateTime.Date)
                            .Every(chore.RepeatingEvery)
                            .Days()
                            //.Ending(checkDate.Date.AddDays(1))

                            .Build();
                var next = daily.Next(checkDate.AddDays(-1));
                if (next.HasValue)
                {
                    return(next.Value.Date == checkDate.Date);
                }
                else
                {
                    return(false);
                }
            }

            if (chore.RepeatingUnit == RepeatingUnitType.Week)
            {
                var weekly = Recurs.Starting(chore.StartDateTime.Date)
                             .Every(chore.RepeatingEvery)
                             .Weeks()
                             .OnDays((Day)chore.RepeatingDaysOfWeek)
                             .Build();
                var next = weekly.Next(checkDate.AddDays(-1));
                if (next.HasValue)
                {
                    return(next.Value.Date == checkDate.Date);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Exemplo n.º 18
0
        public void Daily_EndAfterNumOfOccurences()
        {
            IRecurring daily = Recurs
                               .Starting(new DateTime(2015, 1, 1))
                               .Every(2)
                               .Days()
                               .Ending(2)
                               .Build();

            Assert.Equal(new DateTime(2015, 1, 1), daily.Next(new DateTime(2014, 7, 3)));
            Assert.Equal(new DateTime(2015, 1, 3), daily.Next(new DateTime(2015, 1, 1)));
            Assert.Null(daily.Next(new DateTime(2015, 1, 3)));
        }
        public void Weekly_EndAfterNumOfOccurences()
        {
            IRecurring weekly = Recurs
                                .Starting(new DateTime(2015, 1, 2))
                                .Every(3)
                                .Weeks()
                                .OnDays(Day.TUESDAY | Day.FRIDAY)
                                .Ending(2)
                                .Build();

            Assert.Equal(new DateTime(2015, 1, 2), weekly.Next(new DateTime(2014, 7, 3)));
            Assert.Equal(new DateTime(2015, 1, 20), weekly.Next(new DateTime(2015, 1, 2)));
            Assert.Null(weekly.Next(new DateTime(2015, 1, 20)));
        }
        public void Monthly_EndAfterNumOfOccurences()
        {
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2015, 1, 24))
                                 .Every(2)
                                 .Months()
                                 .OnDay(24)
                                 .Ending(2)
                                 .Build();

            Assert.Equal(new DateTime(2015, 1, 24), monthly.Next(new DateTime(2014, 1, 1)));
            Assert.Equal(new DateTime(2015, 3, 24), monthly.Next(new DateTime(2015, 1, 24)));
            Assert.Null(monthly.Next(new DateTime(2015, 3, 24)));
        }
Exemplo n.º 21
0
        public void Yearly_EndAfterNumOfOccurences2()
        {
            IRecurring recur = Recurs
                               .Starting(new DateTime(2015, 1, 24))
                               .Every(1)
                               .Years()
                               .OnDay(24)
                               .Ending(3)
                               .Build();

            Assert.Equal(new DateTime(2015, 1, 24), recur.Next(new DateTime(2014, 2, 1)));
            Assert.Equal(new DateTime(2016, 1, 24), recur.Next(new DateTime(2015, 1, 24)));
            Assert.Equal(new DateTime(2017, 1, 24), recur.Next(new DateTime(2016, 1, 24)));
            Assert.Null(recur.Next(new DateTime(2017, 1, 24)));
        }
Exemplo n.º 22
0
        public void Daily_EveryThirdDay()
        {
            // Arrange.
            IRecurring daily = Recurs
                               .Starting(new DateTime(2015, 1, 1))
                               .Every(3)
                               .Days()
                               .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 1), daily.Next(new DateTime(2014, 7, 3)));
            Assert.Equal(new DateTime(2015, 1, 4), daily.Next(new DateTime(2015, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 7), daily.Next(new DateTime(2015, 1, 5)));
        }
Exemplo n.º 23
0
        public void Monthly_EveryLastMonth_Ordinal_SameDay()
        {
            // Arrange.
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2019, 04, 30, 13, 00, 00)) // Tuesday
                                 .Every(1)
                                 .Months()
                                 .OnOrdinalWeek(Ordinal.LAST)
                                 .OnDay(DayOfWeek.Monday)
                                 .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2019, 05, 27, 13, 00, 00), monthly.Next(new DateTime(2019, 05, 27, 09, 00, 00)));
        }
Exemplo n.º 24
0
        public void Monthly_EveryFirstMonth_Ordinal_SameDay()
        {
            // Arrange.
            IRecurring monthly = Recurs
                                 .Starting(new DateTime(2020, 04, 06, 13, 00, 00)) // Monday
                                 .Every(1)
                                 .Months()
                                 .OnOrdinalWeek(Ordinal.FIRST)
                                 .OnDay(DayOfWeek.Monday)
                                 .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2020, 05, 04, 13, 00, 00), monthly.Next(new DateTime(2020, 04, 06, 14, 00, 00)));
        }
Exemplo n.º 25
0
        public void Daily_EveryDay_WithTime()
        {
            // Arrange.
            IRecurring daily = Recurs
                               .Starting(new DateTime(2020, 04, 06, 10, 00, 00))
                               .Every(1)
                               .Days()
                               .Ending(new DateTime(2021, 1, 15))
                               .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2020, 04, 06, 10, 00, 00), daily.Next(new DateTime(2020, 04, 06, 09, 00, 00))); // Before start
            Assert.Equal(new DateTime(2020, 04, 07, 10, 00, 00), daily.Next(new DateTime(2020, 04, 06, 10, 00, 00))); // On Start
            Assert.Equal(new DateTime(2020, 04, 07, 10, 00, 00), daily.Next(new DateTime(2020, 04, 06, 11, 00, 00))); // After Start
        }
Exemplo n.º 26
0
        public void Daily_EveryThirdDay_ExcludeWeekends()
        {
            // Arrange.
            IRecurring daily = Recurs
                               .Starting(new DateTime(2015, 1, 1))
                               .Every(3)
                               .Days()
                               .Including(Day.MONDAY | Day.TUESDAY | Day.WEDNESDAY | Day.THURSDAY | Day.FRIDAY)
                               .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2015, 1, 1), daily.Next(new DateTime(2014, 7, 3)));
            Assert.Equal(new DateTime(2015, 1, 6), daily.Next(new DateTime(2015, 1, 1)));
            Assert.Equal(new DateTime(2015, 1, 9), daily.Next(new DateTime(2015, 1, 6)));
            Assert.Equal(new DateTime(2015, 1, 14), daily.Next(new DateTime(2015, 1, 9)));
        }
Exemplo n.º 27
0
        public void Yearly_EndAfterNumOfOccurences()
        {
            IRecurring recur = Recurs
                               .Starting(new DateTime(2015, 1, 1))
                               .Every(3)
                               .Years()
                               .OnDay(24)
                               .OnMonths(Month.JANUARY | Month.FEBRUARY | Month.AUGUST)
                               .Ending(6)
                               .Build();

            Assert.Equal(new DateTime(2015, 1, 24), recur.Next(new DateTime(2014, 2, 1)));
            Assert.Equal(new DateTime(2015, 2, 24), recur.Next(new DateTime(2015, 1, 24)));
            Assert.Equal(new DateTime(2015, 8, 24), recur.Next(new DateTime(2015, 2, 24)));
            Assert.Equal(new DateTime(2018, 1, 24), recur.Next(new DateTime(2015, 8, 24)));
            Assert.Equal(new DateTime(2018, 2, 24), recur.Next(new DateTime(2018, 1, 24)));
            Assert.Equal(new DateTime(2018, 8, 24), recur.Next(new DateTime(2018, 2, 24)));
            Assert.Null(recur.Next(new DateTime(2018, 8, 24)));
        }
Exemplo n.º 28
0
        public void Weekly_Every2Weeks_SunMon()
        {
            // Arrange.
            DateTime startDate = new DateTime(2018, 2, 22);

            IRecurring weekly = Recurs
                                .Starting(startDate)
                                .Every(2)
                                .Weeks()
                                .FirstDayOfWeek(DayOfWeek.Monday)
                                .OnDays(Day.SUNDAY | Day.MONDAY)
                                .Ending(new DateTime(2018, 8, 28))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2018, 2, 25), weekly.Next(new DateTime(2018, 2, 24)));
            Assert.Equal(new DateTime(2018, 3, 5), weekly.Next(new DateTime(2018, 2, 25)));

            Assert.Equal(new DateTime(2018, 3, 5), weekly.Next(new DateTime(2018, 3, 3)));
            Assert.Equal(new DateTime(2018, 3, 11), weekly.Next(new DateTime(2018, 3, 5)));

            Assert.Equal(new DateTime(2018, 3, 19), weekly.Next(new DateTime(2018, 3, 11)));
            Assert.Equal(new DateTime(2018, 3, 25), weekly.Next(new DateTime(2018, 3, 20)));

            Assert.Equal(new DateTime(2018, 4, 2), weekly.Next(new DateTime(2018, 4, 1)));
            Assert.Equal(new DateTime(2018, 4, 8), weekly.Next(new DateTime(2018, 4, 3)));

            Assert.Null(weekly.Next(new DateTime(2018, 8, 28)));

            Assert.Equal(new DateTime(2018, 2, 25), weekly.Previous(new DateTime(2018, 2, 26)));
            Assert.Equal(new DateTime(2018, 3, 5), weekly.Previous(new DateTime(2018, 3, 6)));
            Assert.Equal(new DateTime(2018, 3, 5), weekly.Previous(new DateTime(2018, 3, 11)));
            Assert.Equal(new DateTime(2018, 3, 11), weekly.Previous(new DateTime(2018, 3, 12)));
            Assert.Equal(new DateTime(2018, 3, 19), weekly.Previous(new DateTime(2018, 3, 25)));
            Assert.Equal(new DateTime(2018, 3, 25), weekly.Previous(new DateTime(2018, 4, 2)));
            Assert.Equal(new DateTime(2018, 4, 2), weekly.Previous(new DateTime(2018, 4, 3)));
            Assert.Equal(new DateTime(2018, 4, 8), weekly.Previous(new DateTime(2018, 4, 9)));

            Assert.Null(weekly.Previous(new DateTime(2018, 2, 25)));
        }
Exemplo n.º 29
0
        public void Yearly_EveryYear_Ordinal_Today()
        {
            // Arrange.
            var startDate = new DateTime(2019, 1, 1, 12, 00, 00);

            IRecurring yearly = Recurs
                                .Starting(startDate)
                                .Every(1)
                                .Years()
                                .OnOrdinalWeek(Ordinal.FIRST)
                                .OnDay(DayOfWeek.Monday)
                                .OnMonths(Month.JANUARY)
                                .Ending(new DateTime(2030, 1, 1))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2020, 01, 6, 12, 00, 00), yearly.Next(new DateTime(2020, 01, 06, 08, 00, 00)));
        }
Exemplo n.º 30
0
        public void Weekly_EveryWeek_SameTimeAsDateTime()
        {
            // Arrange.
            DateTime startDate = new DateTime(2020, 04, 06, 10, 00, 00);

            IRecurring weekly = Recurs
                                .Starting(startDate)
                                .Every(1)
                                .Weeks()
                                .OnDay(DayOfWeek.Monday)
                                .Ending(new DateTime(2021, 2, 19))
                                .Build();

            // Act.

            // Assert.
            Assert.Equal(new DateTime(2020, 04, 13, 10, 00, 00), weekly.Next(new DateTime(2020, 04, 06, 11, 00, 00)));
            Assert.Equal(new DateTime(2020, 04, 20, 10, 00, 00), weekly.Next(new DateTime(2020, 04, 13, 10, 00, 00)));
            Assert.Equal(new DateTime(2020, 04, 20, 10, 00, 00), weekly.Next(new DateTime(2020, 04, 20, 09, 00, 00)));
        }