コード例 #1
0
        public void ExtractSingle()
        {
            IEnumerable <DateTime> x = DateTimeExtractor.Extract("Wake me up seven thirty tomorrow");
            DateTime dt = x.First();

            Assert.AreEqual(
                DateTime.Now.Date.AddDays(1).AddHours(7).AddMinutes(30),
                new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second));
        }
コード例 #2
0
 public IEnumerable <DateTime> Get(string s, string dt)
 {
     return(DateTimeExtractor.Extract(
                s,
                DateTime.ParseExact(dt,
                                    "s",
                                    CultureInfo.InvariantCulture,
                                    DateTimeStyles.None)));
 }
コード例 #3
0
        public void ExtractWord()
        {
            IEnumerable <DateTime> x = DateTimeExtractor.Extract("Tomorrow");
            DateTime dt  = x.First();
            DateTime ans = DateTime.Now.AddDays(1);

            Assert.AreEqual(
                new DateTime(ans.Year, ans.Month, ans.Day, ans.Hour, ans.Minute, ans.Second),
                new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second));
        }
コード例 #4
0
        public void ExtractDoubleNumeric()
        {
            IEnumerable <DateTime> x = DateTimeExtractor.Extract("Wake me up 7:30 tomorrow morning and 3:00 tomorrow afternoon");
            DateTime dt  = x.First();
            DateTime dt2 = x.Skip(1).First();

            Assert.AreEqual(
                DateTime.Now.Date.AddDays(1).AddHours(7).AddMinutes(30),
                new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second));
            Assert.AreEqual(
                DateTime.Now.Date.AddDays(1).AddHours(15),
                new DateTime(dt2.Year, dt2.Month, dt2.Day, dt2.Hour, dt2.Minute, dt2.Second));
        }
コード例 #5
0
 static void Main(string[] args)
 {
     while (true)
     {
         Console.Write("{0}: Your message > ", DateTime.Now.ToString("yyyy/MM/dd HH:mm"));
         string s = Console.ReadLine();
         foreach (DateTime dt in DateTimeExtractor.Extract(s))
         {
             Console.WriteLine("Found {0}", dt.ToString("yyyy/MM/dd HH:mm"));
         }
         Console.WriteLine();
     }
 }