[Rails] bug in postgresql 'now' time handling??
Ara.T.Howard
Ara.T.Howard at noaa.gov
Fri Mar 4 17:58:43 GMT 2005
On Fri, 4 Mar 2005, Dave Steinberg wrote:
> What if there was a way to supply 'Time.now' to the ruby world and the
> string 'now' to the database (covering the unsaved object case). Then if we
> reload newly saved objects, we'd be completely in sync.
that'd be pretty easy:
def default_values value
...
when /now/
now = Time::now
class << now
def bi_polar_to_s
'now'
end
end
now
...
end
...
def rails_obj_to_rdbms_mapping value
meth =
if value.respond_to? 'bi_polar_to_s'
'bi_polar_to_s'
...
...
value.send meth
end
so conceptually mark objects that that need this split to_s functionality -
one to_s in rails-land and another in db-land. i don't know where the second
half takes place or my example might make more sense but maybe it's clear
enough?
> While reading through the docs yesterday, I literally laughed out loud at
> the last one. We could provide some ruby-equivelant constants for most of
> those, obviously the tricky ones are now, and +/- infinity. For the others,
> a patch would be easy.
to really handle +/- infinity i think you need to extend the built in time
class to be able to handle two special singleton objects with appropriate
comparisson semantics (alwasy less/greater than every other time except
themselves) AND a special string representation - maybe
'0000-00-00 00:00:00-00'
and
'9999-99-99 99:99:99-99'
since these are practically impossible... everytime i've tackled this before
i've given up though. time can be so tricky to manage (no pun intended).
> Agreed. When I came to the code, they weren't there, and I wasn't familiar
> with them, so I just handled 'now' as best I could. I think they come back
> as strings more for accidental reasons than intentional ones.
fair enough.
> Any ideas how we could handle this gracefully? In my own code I've dealt
> with the inability of ruby's Time object to just specify a time without a
> date, so if we've got several problems with this object, perhaps we look
> towards supplying a more full-featured one. Ideas?
maybe a TimeStamp object? this might be a really clean solution - but a bit
of work and thinking...
>> at this point in half-agreement with Dave Lee; i don't think 'now' should
>> come back as a string - rather it should come back as a string like the
>> rest of of the special time values. this is the simplest solution that is
>> totally correct IMHO.
>
> Yes, but the least sublime. At the very least, we should recognize the
> other special keywords and provide Time object equivalents for them and
> return the others as strings. If we do return 'now' as a string, we ought
> to update the helpers so that they can deal with it.
i agree that it would be nice to give something other than a string and now
agreed that it's o.k. to have approximations at the presentation (rails-to_s)
level - so long as the db stays consistent in the end. this is a 'wiki-able'
oddity most people should be able to grasp...
> Few seem to be chiming in. I'll try and post a patch with the easy keywords
> properly adjusted, and I'll try and play around with a split representation
> for now.
o.k. then - i really need to read some more source before i can suggest any
objectification of the problem. i've got to do some rails stuff this weekend
so i'll poke around then and mull some more.
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