SIL.FieldWorks.Filters.DateTimeMatcher.Matches C# (CSharp) Method

Matches() public method

public Matches ( ITsString arg ) : bool
arg ITsString
return bool
		public override bool Matches(ITsString arg)
		{
			string text = arg.Text;
			if (String.IsNullOrEmpty(text))
				return false;
			DateTime time;
			GenDate gen;
			if (!HandleGenDate && DateTime.TryParse(text, out time))
			{
				switch (m_type)
				{
					case DateMatchType.After:
						return time >= m_start;
					case DateMatchType.Before:
						return time <= m_end;
					case DateMatchType.Range:
					case DateMatchType.On:
						return time >= m_start && time <= m_end;
					case DateMatchType.NotRange:
						return time < m_start || time > m_end;
				}
			}
			else if (HandleGenDate && GenDate.TryParse(text, out gen))
			{
				switch (m_type)
				{
					case DateMatchType.After:
						return GenDateIsAfterDate(gen, m_start, IsStartAD);
					case DateMatchType.Before:
						return GenDateIsBeforeDate(gen, m_end, IsEndAD);
					case DateMatchType.Range:
					case DateMatchType.On:
						return GenDateIsInRange(gen);
					case DateMatchType.NotRange:
						return !GenDateIsInRange(gen);
				}
			}
			return false;
		}

Usage Example

        public void MatchBefore()
        {
            var matchBefore = new DateTimeMatcher(new DateTime(1990, 1, 17, 0, 0, 0),
                                                  new DateTime(1990, 1, 17, 23, 59, 59), DateTimeMatcher.DateMatchType.Before)
            {
                HandleGenDate = true
            };

            var fMatch = matchBefore.Matches(m_tsf.MakeString("January, 1990", DateTimeMatcherTests.WsDummy));

            Assert.IsFalse(fMatch, "January, 1990 not before 1/17/90");
        }
All Usage Examples Of SIL.FieldWorks.Filters.DateTimeMatcher::Matches