[Rails] uniform handling of timestamps

Ara.T.Howard Ara.T.Howard at noaa.gov
Thu Mar 3 16:42:29 GMT 2005


considering that sqlite, mysql, postgresql, etc all handle times differently
(well only postgresql really *handles* them) i'm wondering how to best
approach time fields in rails.  my current thinking is that sqlite is the
least common denominator: it stores everything as text and does not checking,
mysql has datetime, date, and timestamp but does poor checking (crippled to be
precise) to ensure the column is valid.  only postgresql supports both
timestamps AND will ensure the field value is a possible date/time.  enter
rails and it's mapping to *_at fields.  i'm thinking that seting up a table
like

   create table temporal (
     id int,
     data text,
     created_at text,
     updated_at text

     primary key (id)
   );

should do the trick since rails will pull out the strings and convert them to
times and also update them at the right times.  however, there doesn't seem to
be a validation done automatically on the input values?  hopefully i'm missing
that, but i was hoping to see something like

   require 'time'

   valid =
     begin
       t = Time::parse field
       true
     rescue
       false
     end

somewhere in the source (which is pretty big so i may not have found it).  can
anyone tell me if this happens or not?  it's a bit tricky to test for three
dbs at once...  also, should storing timestamps as text work if the fieldnames
are *_at but the type is text?

cheers.

-a
-- 
===============================================================================
| EMAIL   :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE   :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself.  --Shunryu Suzuki
===============================================================================


More information about the Rails mailing list