On Jun 2, 6:59 pm, Jeremy Evans <[EMAIL PROTECTED]> wrote:
> The value you get from the database is adapter specific (I think Time
> is used in most cases).  When using models with typecasting, it will
> always cast to a DateTime and not a Time.  I'll accept patches for
> adapters to use a DateTime field instead of a Time field.

I've found some inconsistent code with Sequel's handling of Time and
DateTime. I have an Organisation class that sets the created_at and
updated_at fields when the object is created and subsequently updated.
When an object is created the class of updated_at is Time. On a
subsequent save it becomes DateTime and after the model is reloaded it
switches back to Time. Below is a capture of an IRb session which
shows this.

irb(main):001:0> o = Organisation.create
 ~ INSERT INTO "organisations" ("created_at", "updated_at", "active",
"uuid") VALUES (TIMESTAMP '2008-06-03 22:07:21.000000', TIMESTAMP
'2008-06-03 22:07:21.000000', true, 'c214427f-a82e-4f14-a7e2-
cf2d1d1d2815')
 ~ SELECT * FROM "organisations" WHERE ("id" = 2) LIMIT 1
=> #<Organisation
@values={:admin_user_id=>nil, :phone_number=>nil, :fax_number=>nil, 
:created_at=>Tue
Jun 03 22:07:21 +0200 2008, :name=>nil, :updated_at=>Tue Jun 03
22:07:21 +0200
2008, :postal_address=>nil, :active=>true, :street_address=>nil, 
:uuid=>"c214427f-
a82e-4f14-a7e2-cf2d1d1d2815", :email_address=>nil, :id=>2}>
irb(main):002:0> o.created_at.class
=> Time
irb(main):003:0> o.updated_at.class
=> Time
irb(main):004:0> o.name = "test"
=> "test"
irb(main):005:0> o.save
 ~ UPDATE "organisations" SET "admin_user_id" = NULL, "phone_number" =
NULL, "fax_number" = NULL, "created_at" = TIMESTAMP '2008-06-03
22:07:21.000000', "name" = 'test', "updated_at" = TIMESTAMP
'2008-06-03 22:07:52.000000', "postal_address" = NULL, "active" =
true, "street_address" = NULL, "uuid" = 'c214427f-a82e-4f14-a7e2-
cf2d1d1d2815', "email_address" = NULL, "id" = 2 WHERE ("id" = 2)
=> #<Organisation
@values={:admin_user_id=>nil, :phone_number=>nil, :fax_number=>nil, 
:created_at=>Tue
Jun 03 22:07:21 +0200 2008, :name=>"test", :updated_at=>#<DateTime:
26509911359/10800,0,2299161>, :postal_address=>nil, :active=>true, 
:street_address=>nil, :uuid=>"c214427f-
a82e-4f14-a7e2-cf2d1d1d2815", :email_address=>nil, :id=>2}>
irb(main):006:0> o.created_at.class
=> Time
irb(main):007:0> o.updated_at.class
=> DateTime
irb(main):008:0> o.reload
 ~ SELECT * FROM "organisations" WHERE ("id" = 2) LIMIT 1
=> #<Organisation
@values={:admin_user_id=>nil, :phone_number=>nil, :fax_number=>nil, 
:created_at=>Tue
Jun 03 22:07:21 +0200 2008, :name=>"test", :updated_at=>Tue Jun 03
22:07:52 +0200
2008, :postal_address=>nil, :active=>true, :street_address=>nil, 
:uuid=>"c214427f-
a82e-4f14-a7e2-cf2d1d1d2815", :email_address=>nil, :id=>2}>
irb(main):009:0> o.updated_at.class
=> Time

On line 3 and line 9 a A Time class is returned as the class of
updated_at, while on line 7 it's a DateTime.

Farrel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to sequel-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to