Natural language parser for dates (.NET)?

孤人 提交于 2019-12-03 07:38:23

I know it's not an optimal solution but you can also try to port the dateJs library to .net

It handles things like today; tomorrow; July 2008; next friday; last April; 2004.08.07; 6/4/2005; 8:15 PM; 22:30:45; +5years

I don't know of anything that you can use with the framework today that will allow you to do this, but if you are content with playing around with future bits, you can check out Oslo, and make your own textual DSL.

This article shows how to do exactly what you are trying to do:

http://www.infoq.com/articles/natural-language-date-dsl-oslo

DateTime.Parse() will take a string argument and attempt to generate its DateTime equal. I'm a bit rusty on it, but it should work for any date string which you can generate with DateTime.ToString().

You can also take a look at DateTime.ParseExact() which does the same thing as Parse(), but allows you to restrict the possible formats for the input string. The following link should help you out with both as well as any other date parsing functions in the framework.

http://msdn.microsoft.com/en-us/library/1k1skd40.aspx

Eric

We developed exactly what you are looking for on an internal project. We are thinking of making this public if there is sufficient need for it. Take a look at this blog for more details: http://precisionsoftwaredesign.com/blog.php.

I've built this library as part of a project at work. It's not totally polished but if you are interested, I can put some more work into it and/or arrange a license for your needs.

Very old program I wrote (using Clipper, an DBASE derivative), but the code is pretty readable.

http://www.jbooth-consulting.com/downloads/clipper/guessdate.zip

Might give you some ideas if you want to roll your own...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!