コード例 #1
0
        /// <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);
        }
コード例 #2
0
 public void CtorTests()
 {
     _ = new LeapYearMatcher(null, null);
     _ = new LeapYearMatcher(2000, null);
     _ = new LeapYearMatcher(null, 2000);
     _ = new LeapYearMatcher(2000, 3000);
     Assert.ThrowsException <ArgumentException>(() => new LeapYearMatcher(2000, 2000));
 }
コード例 #3
0
        public void MatchTests()
        {
            var lym    = new LeapYearMatcher(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.IsTrue(lym.Match(dt2000));
            Assert.IsFalse(lym.Match(dt2001));
            Assert.IsTrue(lym.Match(dt2020));
            Assert.IsFalse(lym.Match(dt2100));
        }
コード例 #4
0
        public void TryParseTests()
        {
            // Testing object factory (valid)
            Assert.IsTrue(LeapYearMatcher.TryParse("*/Leap", out var lym));
            Assert.IsNotNull(lym);
            Assert.IsNull(lym.Left);
            Assert.IsNull(lym.Right);
            Assert.IsTrue(LeapYearMatcher.TryParse("1..100/Leap", out lym));
            Assert.IsNotNull(lym);
            Assert.AreEqual(1, lym.Left);
            Assert.AreEqual(100, lym.Right);

            // Testing object factory (invalid)
            Assert.IsFalse(LeapYearMatcher.TryParse("/Leap", out lym));
            Assert.IsNull(lym);
            Assert.IsFalse(LeapYearMatcher.TryParse("12/Leap", out lym));
            Assert.IsNull(lym);
            Assert.IsFalse(LeapYearMatcher.TryParse("12..12/Leap", out lym));
            Assert.IsNull(lym);
        }