# Date/Time Quick Add

**URL:** <https://www.ruby-forum.com/t/date-time-quick-add/60719>\
**Category:** Rails\
**Created:** [May 17, 2006, 12:07am UTC](https://www.ruby-forum.com/t/date-time-quick-add/60719 "2006-05-17T00:07:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stirman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stirman](https://www.ruby-forum.com/u/stirman)\
**Post date:** [May 17, 2006, 12:07am UTC](https://www.ruby-forum.com/t/date-time-quick-add/60719/1 "2006-05-17T00:07:52Z")

</div>

I am building a small app that reuires some clever text pattern  
matching…

In my controller, I’ll have a string that I will want to parse out to a  
datetime and a message, a la Google C. Quick Add.

Examples:

10/30/2006 7pm message  
10-30-96 7:00 pm message  
10/30/2006 19:00pm message  
…

You see what I’m getting at. For a v1.0 release, I CAN publish some  
standards for users to adhere to regarding how the string should look,  
but I’m wondering how some more experienced programmers might attack  
this problem, from a high level view. What do you initially look for,  
what do you delimit on, how do you break the string up, etc.

Would love some feedback, many thanks in advance!

-stirman

---

<div class="post-metadata">

**Author:** ![stirman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stirman](https://www.ruby-forum.com/u/stirman)\
**Post date:** [May 17, 2006, 2:59am UTC](https://www.ruby-forum.com/t/date-time-quick-add/60719/2 "2006-05-17T02:59:01Z")

</div>

Have a look at my validates\_date\_time plugin

[http://svn.viney.net.nz/things/rails/plugins/validates\_date\_time](http://svn.viney.net.nz/things/rails/plugins/validates_date_time)

-Jonathan.

---

<div class="post-metadata">

**Author:** ![stirman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stirman](https://www.ruby-forum.com/u/stirman)\
**Post date:** [May 17, 2006, 4:16am UTC](https://www.ruby-forum.com/t/date-time-quick-add/60719/3 "2006-05-17T04:16:53Z")

</div>

Jeepers, that’s pretty nice.

Have you looked at DateboxEngine?

[http://rails-engines.org/wiki/pages/DateboxEngine](http://rails-engines.org/wiki/pages/DateboxEngine)

It only handles dates, not times, and does it in Javascript… but you  
might want to investigate some of the patterns it recognizes, like “next  
tuesday”, “last monday” and month and date with an implicit year.

Jonathan V. wrote:

> Have a look at my validates\_date\_time plugin
> 
> [http://svn.viney.net.nz/things/rails/plugins/validates\_date\_time](http://svn.viney.net.nz/things/rails/plugins/validates_date_time)
> 
> -Jonathan.

---

<div class="post-metadata">

**Author:** ![stirman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stirman](https://www.ruby-forum.com/u/stirman)\
**Post date:** [May 17, 2006, 4:02pm UTC](https://www.ruby-forum.com/t/date-time-quick-add/60719/4 "2006-05-17T16:02:26Z")

</div>

Wow, great plugin…

Today I’ll be sorting through the code to see how I can apply it to my  
app.

As I learn what you did, I’ll see about writing a patch to include some  
of the above-mentioned functionality.

Many thanks, great work.

-stirman  
[www.stirman.net](http://www.stirman.net)

---

<div class="post-metadata">

**Author:** ![stirman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stirman](https://www.ruby-forum.com/u/stirman)\
**Post date:** [May 17, 2006, 7:48am UTC](https://www.ruby-forum.com/t/date-time-quick-add/60719/5 "2006-05-17T07:48:11Z")

</div>

I’ve found that most users don’t want to type ‘today’, and as I  
usually give them a date picker widget they’re pretty happy to just  
use that.

I wouldn’t be adverse to adding support to parse more english-like  
dates such as ‘today’, ‘last tuesday’ etc…, feel free to write a  
patch if you want.

Parsing with an implicit year is a good idea, I may add that at some  
stage. Again, patches welcome :).

Cheers, Jonathan.
