<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>I.NFECTIO.US: Tag date</title>
    <link>http://i.nfectio.us/articles/tag/date</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>"Nothing in life is worth doing if you have no life while doing it"</description>
    <item>
      <title>Validate Dates in Your Models</title>
      <description>mojombo in #caboose, just released his first version of &lt;a href="http://chronic.rubyforge.org/"&gt;Chronic&lt;/a&gt;, a new Ruby Gem for natural language processing of Dates and Times.

&lt;pre&gt;
gem install chronic

irb:&gt;
Chronic.parse('tomorrow')
    #=&gt; Mon Aug 28 12:00:00 PDT 2006

Chronic.parse('monday', :context =&gt; :past)
    #=&gt; Mon Aug 21 12:00:00 PDT 2006

Chronic.parse('this tuesday 5:00')
    #=&gt; Tue Aug 29 17:00:00 PDT 2006

Chronic.parse('this tuesday 5:00', :ambiguous_time_range =&gt; :none)
    #=&gt; Tue Aug 29 05:00:00 PDT 2006

Chronic.parse('may 27th', :now =&gt; Time.local(2000, 1, 1))
    #=&gt; Sat May 27 12:00:00 PDT 2000

Chronic.parse('may 27th', :guess =&gt; false)
    #=&gt; Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007

&lt;/pre&gt;

The thing I find really nice is that if you pass it a malformed date, it returns nil. This means, in your model validations, you can add:

&lt;pre&gt;
require 'chronic'

class Meeting &lt; ActiveRecord::Base

  def validation
    errors.add :meeting_date, 'is not a valid date' if Chronic.parse(meeting_date.to_s).nil?
  end

end
&lt;/pre&gt;</description>
      <pubDate>Thu, 07 Sep 2006 23:11:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:8014225f-73e7-4d6b-aa0b-35091ad56078</guid>
      <author>Bob Silva</author>
      <link>http://i.nfectio.us/articles/2006/09/07/validate-dates-in-your-models</link>
      <category>Ruby on Rails</category>
      <category>rails</category>
      <category>date</category>
      <category>validation</category>
      <category>activerecord</category>
    </item>
  </channel>
</rss>
