In all my current projects that use dm-timestamps, I run into an issue
with the use of DateTime. Because, when using the DataObjects
adapter, it saves to a precision of one second, writing specs is very
hard. To prove that one object is saved after another, you have to
introduce a delay of >= 1s to be sure of the order.
However, Time saves to a precision of microseconds. Because of this,
I have the following section in all my Merb init.rb files:
DataMapper::Timestamp::TIMESTAMP_PROPERTIES = {
:updated_at => [ Time, lambda { |r, p| Time.now } ],
:updated_on => [ Date, lambda { |r, p| Date.today } ],
:created_at => [ Time, lambda { |r, p| r.created_at || (Time.now
if r.new_record?) } ],
:created_on => [ Date, lambda { |r, p| r.created_on ||
(Date.today if r.new_record?) } ],
}.freeze
I just wondered, is there any reason why dm-timestamps can't use Time
instead of DateTime by default? It would increase the precision of
the timestamp data, but there may be issues I'm unaware of.
Thanks for any input
Ashley
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
http://twitter.com/ashleymoran
> Even if we did decide to do it, I'd wait until the
> DataMapper::Property class is refactored (it's going to be split up
> into a single base class, and the logic for each primitive separated
> into subclasses). Once this is done it will be much simpler to add
> Time specific casting logic to DateTime::Property::Time for example.
Should I raise a ticket in the mean time to reference this thread, or
hold fire until the related issues are resolved?
Thanks
> When in doubt raise a ticket ;)
I hope you realise how much ticked harassment you've now exposed
yourself to from me =)
> I think in this case it would be totally appropriate to create a
> ticket to remind us to revisit it on the mailing list once
> DM::Property is refactored better.
I will do exactly this!
Cheers
> I think in this case it would be totally appropriate to create a
> ticket to remind us to revisit it on the mailing list once
> DM::Property is refactored better.
Done =)