This project is archived and is in readonly mode.

#2465 ✓invalid
Ashrafuzzaman

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

Reported by Ashrafuzzaman | April 9th, 2009 @ 12:32 PM | in 2.x

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

Comments and changes to this ticket

  • Geoff Buesing

    Geoff Buesing April 9th, 2009 @ 05:13 PM

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

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

  • Ashrafuzzaman

    Ashrafuzzaman April 12th, 2009 @ 10:58 AM

    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).

  • Geoff Buesing

    Geoff Buesing April 12th, 2009 @ 02:29 PM

    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) %>

  • Geoff Buesing

    Geoff Buesing April 12th, 2009 @ 02:30 PM

    • State changed from “new” to “invalid”
  • Ashrafuzzaman

    Ashrafuzzaman April 13th, 2009 @ 05:12 AM

    • Tag set to 2.3.1

    Thanks It resolved the issue.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Tags

Pages