/// <summary>
        ///     Parse a year match expression.
        ///     <example>
        ///         Valid expression are:
        ///         * => Every year
        ///         2020 => Exactly that year
        ///         ..2030 => Every year until 2030 comprised
        ///         2020.. => Every year starting from 2020
        ///         2020..2030 => Every year between 2020 and 2030
        ///         */Leap => Every leap year
        ///         2020..2030/Leap => Every leap year between 2020 and 2030
        ///         */NotLeap => Every non leap year
        ///         2020..2030/2 => Starting from 2020 every 2 years until 2030
        ///         2020../2 => Starting from 2020 every 2 years
        ///         2020../NotLeap => Starting from 2020 every NonLeap year
        ///         2020..2030%2 => Every year which reminder modulo 2 is zero between 2020 and 2030
        ///         2020..%3 => Starting from 2020 every year which reminder modulo 3 is zero
        ///     </example>
        /// </summary>
        public override bool TryParse(string value, out IYearMatcher yearMatcher)
        {
            if (RangeYearMatcher.TryParse(value, out var rangeYearMatcher))
            {
                yearMatcher = rangeYearMatcher;
                return(true);
            }

            if (PeriodicYearMatcher.TryParse(value, out var periodYearMatcher))
            {
                yearMatcher = periodYearMatcher;
                return(true);
            }

            if (ModuloYearMatcher.TryParse(value, out var moduloYearMatcher))
            {
                yearMatcher = moduloYearMatcher;
                return(true);
            }

            if (LeapYearMatcher.TryParse(value, out var leapYearMatcher))
            {
                yearMatcher = leapYearMatcher;
                return(true);
            }

            if (NotLeapYearMatcher.TryParse(value, out var notLeapYearMatcher))
            {
                yearMatcher = notLeapYearMatcher;
                return(true);
            }

            yearMatcher = default;
            return(false);
        }
Beispiel #2
0
 public void CtorTests()
 {
     _ = new NotLeapYearMatcher(null, null);
     _ = new NotLeapYearMatcher(2000, null);
     _ = new NotLeapYearMatcher(null, 2000);
     _ = new NotLeapYearMatcher(2000, 3000);
     Assert.ThrowsException <ArgumentException>(() => new NotLeapYearMatcher(2000, 2000));
 }
Beispiel #3
0
        public void MatchTests()
        {
            var obj    = new NotLeapYearMatcher(null, null);
            var dt2000 = new DateTime(2000, 1, 1);
            var dt2001 = new DateTime(2001, 1, 1);
            var dt2020 = new DateTime(2020, 1, 1);
            var dt2100 = new DateTime(2100, 1, 1);

            Assert.IsFalse(obj.Match(dt2000));
            Assert.IsTrue(obj.Match(dt2001));
            Assert.IsFalse(obj.Match(dt2020));
            Assert.IsTrue(obj.Match(dt2100));
        }
Beispiel #4
0
        public void TryParseTests()
        {
            // Testing object factory (valid)
            Assert.IsTrue(NotLeapYearMatcher.TryParse("*/NotLeap", out var obj));
            Assert.IsNotNull(obj);
            Assert.IsNull(obj.Left);
            Assert.IsNull(obj.Right);
            Assert.IsTrue(NotLeapYearMatcher.TryParse("1..100/NotLeap", out obj));
            Assert.IsNotNull(obj);
            Assert.AreEqual(1, obj.Left);
            Assert.AreEqual(100, obj.Right);

            // Testing object factory (invalid)
            Assert.IsFalse(NotLeapYearMatcher.TryParse("/NotLeap", out obj));
            Assert.IsNull(obj);
            Assert.IsFalse(NotLeapYearMatcher.TryParse("12/NotLeap", out obj));
            Assert.IsNull(obj);
            Assert.IsFalse(NotLeapYearMatcher.TryParse("12..12/NotLeap", out obj));
            Assert.IsNull(obj);
        }