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 Hallstrom <rails@philip.pjkh.com> 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.htmlPhilip, 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
Sounds like a great opportunity for a plugin. On 5/11/06, Isaac Reuben <isaac@reuben.com> wrote:> > On 5/11/06, Philip Hallstrom <rails@philip.pjkh.com> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060511/417d6dc6/attachment.html
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. On 5/12/06, Eden Brandeis <ebrandeis@gmail.com> wrote:> Sounds like a great opportunity for a plugin. > > > On 5/11/06, Isaac Reuben <isaac@reuben.com> wrote: > > On 5/11/06, Philip Hallstrom <rails@philip.pjkh.com> 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 > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >