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)); }
public IEnumerable <DateTime> Get(string s, string dt) { return(DateTimeExtractor.Extract( s, DateTime.ParseExact(dt, "s", CultureInfo.InvariantCulture, DateTimeStyles.None))); }
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)); }
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)); }
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(); } }