Forum: Ruby on Rails string to date/time?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Isaac R. (Guest)
on 2006-05-11 16:50
(Received via mailing list)
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
Philip H. (Guest)
on 2006-05-11 22:02
(Received via mailing list)
> 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/C...

-philip
Isaac R. (Guest)
on 2006-05-12 00:19
(Received via mailing list)
On 5/11/06, Philip H. <removed_email_address@domain.invalid> 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/C...

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
Eden B. (Guest)
on 2006-05-12 00:29
(Received via mailing list)
Sounds like a great opportunity for a plugin.
Jonathan V. (Guest)
on 2006-05-12 05:26
(Received via mailing list)
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/valid...

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.
This topic is locked and can not be replied to.