Developing on Staxmanade

NuGet Project Uncovered: Chronic

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Chronic is a port of Ruby’s Chronic providing some natural language parsing for dates.

This is a pretty cool little utility as it lets you take some input like "tomorrow” or “two weeks ago” and turn that into a DateTime object.

Take a look at some tests I pulled from https://github.com/robertwilczynski/nChronic/blob/master/src/Chronic.Tests/CustomParsingTest.cs.

[Fact]
public void seven_days_from_now_at_midnight()
{
Parse(" seven days from now at midnight")
.AssertEquals(Time.New(2006, 8, 24));
}

[Fact]
public void _2_weeks_ago()
{
Parse("2 weeks ago")
.AssertEquals(Time.New(2006, 8, 02, 14));
}

[Fact]
public void two_weeks_ago()
{
Parse("two weeks ago")
.AssertEquals(Time.New(2006, 8, 02, 14));

I tried playing with it a bit. There seem to be some cases sensitivity issues with the codebase now as “tomorrow” works but “Tomorrow” doesn’t. But I think that’s a great reason to be on GitHub. Fork, fix, and send a pull request. All better…

Comments