String to date/time?

Hey All,

Anyone know of a library for parsing “human” dates, like “this friday”
or “2 days ago”? I used to use strtotime in php, but starting from
here;

http://wiki.rubyonrails.com/rails/pages/PhpStrtotime

and doing lots of googling, I haven’t been able to find anything
similar for ruby. I know of javascript solutions to this, but I’d
need to do this processing on the server.

Thanks!

  • Isaac

Anyone know of a library for parsing “human” dates, like “this friday”
or “2 days ago”? I used to use strtotime in php, but starting from
here;

Have not used it myself, but…

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Conversions.html

-philip

On 5/11/06, Philip H. [email protected] wrote:

Anyone know of a library for parsing “human” dates, like “this friday”
or “2 days ago”? I used to use strtotime in php, but starting from
here;

Have not used it myself, but…

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Conversions.html

Philip, thanks for the reference. Unfortunately those methods use
ParseDate.parsedate, which is good for converting formatted date/times
that are strings like “Sat May 14 19:28:13 IST 2005”, but it doesn’t
understand common language formats, like “this friday” or “today”.

  • Isaac

My validates_date_time plugin understands common formats like:

1 Jan 06
2006-01-01
1 January 2006
1/1/06

And could easily be extended to parse strings such as ‘today’, ‘this
friday’ etc… by extending the parsing a bit.

Have a go and send me a patch if you want:

http://svn.viney.net.nz/things/rails/plugins/validates_date_time

The problem with the String#to_date and String#to_time is that they
are too lenient and often guess wrongly given ambiguous input.

-Jonathan.

Sounds like a great opportunity for a plugin.