示例#1
0
        private IEnumerable <TemporalComponent> GetComponentsFromText(string text)
        {
            var components = new List <TemporalComponent>();

            var dateComponents = DateComponent.GetComponentsFromText(text);

            components.AddRange(dateComponents);

            var timeComponents = TimeComponent.GetComponentsFromText(text);

            components.AddRange(timeComponents);

            var sequenceComponents = SequenceComponent.GetComponentsFromText(text);

            components.AddRange(sequenceComponents);

            var fuzzyComponents = FuzzyComponent.GetComponentsFromText(text);

            components.AddRange(fuzzyComponents);

            var durationComponents = DurationComponent.GetComponentsFromText(text);

            components.AddRange(durationComponents);

            var relativeComponents = RelativeDateTimeComponent.GetComponentsFromText(text);

            components.AddRange(relativeComponents);

            return(components);
        }
示例#2
0
        private void AssertValidFuzzyComponent(ITimePeriod expected, string input, DateTime baseDate)
        {
            var components = FuzzyComponent.GetComponentsFromText(input);

            Assert.IsTrue(components.Any());
            var componentPeriod = components.FirstOrDefault().GetTimePeriod(baseDate);

            Assert.IsNotNull(componentPeriod);
            Assert.AreEqual(expected.Start, componentPeriod.Start);
            Assert.AreEqual(expected.End, componentPeriod.End);
        }
示例#3
0
        public void GetTimeOfDayPeriodTest()
        {
            var morning = new TimeRange(BaseDate, new TimeSpan(12, 0, 0));

            Assert.AreEqual(morning, FuzzyComponent.GetTimeOfDayPeriod(TimeOfDay.Morning, BaseDate));

            var afternoon = new TimeRange(BaseDate.AddHours(12), new TimeSpan(6, 0, 0));

            Assert.AreEqual(afternoon, FuzzyComponent.GetTimeOfDayPeriod(TimeOfDay.Afternoon, BaseDate));

            var night = new TimeRange(BaseDate.AddHours(18), new TimeSpan(6, 0, 0));

            Assert.AreEqual(night, FuzzyComponent.GetTimeOfDayPeriod(TimeOfDay.Night, BaseDate));
        }