Seek the Wiki page for more information.
1/1/2009, 12:00PM
1/1/2009, 2-3 PM
Jan 1, 2009, 2 to 3 PM
January 1
August 31st
January 1, 2009
January, 2009
June 10-July 1, 2012
Mondays, 6PM
Mondays at 3PM
Every Monday, 6PM
Every Friday
First Monday of every month
Last Sunday of the month
Everyday
Everyday, 2 to 3 PM
1st of the Month
31st of every Month
Attempt to parse a date string:
NaturalDate date;
if (! NaturalDate.TryParse("January 1, 2009, 10-11PM", out date))
{
Console.WriteLine(date.ErrorString);
}
Enumerate a recurring date:
foreach (NaturalDate d in NaturalDate.Enumerate("Every Friday", "January 1, 2009"))
{
Console.WriteLine(d);
}
Find the next occurrence of a recurring date:
Console.WriteLine(NaturalDate.Next("Every Friday at 7PM", "January 1, 2009"));
Using Linq, this example walks the week ahead, starting with today, and finds all events that overlap each day. It assumes EventList is an list of objects containing a 'When' property which is a NaturalDate.
foreach (var day in NaturalDate.Enumerate("everyday", "today").Take(7))
{
var daysEvents = from e in EventList where e.When.Overlaps(day)
orderby e.When.Next(day) select e;
...
}
Anonymous