Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[Rails 2.3.1] Time zone information is not loaded from fixtures

#2465

In rails 2.3.1 I set a datetime field as DateTime.now.utc, But it is not giving the expected result.

Reported by Ashrafuzzaman · April 9th, 2009 @ 12:32 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Geoff Buesing
    Geoff Buesing

    What did you expect, and what did you get instead?

    Try using just Time.now.utc, see if that fixes things.

    April 9th, 2009 @ 05:13 PM

  2. Ashrafuzzaman
    Ashrafuzzaman

    If I use Time.now.utc or Time.now in fixtures where my database field is datetime it gives error,

    ActiveRecord::StatementInvalid: Mysql::Error: Incorrect datetime value: 'Sun Apr 12 11:40:05 UTC 2009' for column 'deadline' at row 1: INSERT INTO job_assignments (job_id, updated_at, id, deadline, transporter_fee, transporter_id, created_at, state) VALUES (245383586, '2009-04-12 09:40:07', 809788707, 'Sun Apr 12 11:40:05 UTC 2009', 75, 468814034, '2009-04-12 09:40:07', 'assigned')

    Let me descripbe the problem in detail. I want to use something like Time.now.utc or DateTime.now.utc in fixtures to get the time with localization support. Using Time.now.utc gives error in fixtures. And using DateTime.now.utc does not give expected output(with timezone information).

    April 12th, 2009 @ 10:58 AM

  3. Geoff Buesing
    Geoff Buesing

    Aha ok -- looks like you're not calling #to_s(:db) -- 'Sun Apr 12 11:40:05 UTC 2009' is the plain Time#to_s output.

    You need to explicitly call #to_s(:db) on time objects that you insert into fixtures via erb, like so:

    deadline: <%= Time.now.utc.to_s(:db) %>

    April 12th, 2009 @ 02:29 PM

  4. Geoff Buesing
    Geoff Buesing
    • State changed from new to invalid

    April 12th, 2009 @ 02:30 PM

  5. Ashrafuzzaman
    Ashrafuzzaman
    • Tag set to 2.3.1

    Thanks It resolved the issue.

    April 13th, 2009 @ 05:12 AM