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.

Time saved as UTC but read as localtime

#4224

Maybe it's a choice, but when you save an object, updated_at for exemple is saved as UTC, but when you do a query for read, time is not converted into UTC time. (sorry for my english !)

Exemple :


d = MyObject.last
=> #

d.created_at => Tue, 16 Mar 2010 15:56:53 UTC +00:00 d.created_at = Time.now => Thu Mar 18 15:01:22 -0400 2010 d.save => true d.created_at => Thu, 18 Mar 2010 19:01:22 UTC +00:00 timestamp = d.created_at.localtime.to_i => 1268938882 Peer.find_by_created_at(timestamp) Peer Load (0.9ms) SELECT * FROM my_objects WHERE (my_objects.created_at = '2010-03-18 15:01:22') LIMIT 1
=> nil

Reported by joserwan · March 18th, 2010 @ 07:18 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. joserwan
    joserwan

    ugly formatting !

    Exemple :

    d = MyObject.last
    => #
    >> d.created_at
    => Tue, 16 Mar 2010 15:56:53 UTC +00:00
    >> d.created_at = Time.now
    => Thu Mar 18 15:01:22 -0400 2010
    >> d.save
    => true
    >> d.created_at
    => Thu, 18 Mar 2010 19:01:22 UTC +00:00
    >> timestamp = d.created_at.localtime.to_i
    => 1268938882
    >> Peer.find_by_created_at(timestamp)
    Peer Load (0.9ms)   SELECT * FROM `my_objects` WHERE (`my_objects`.`created_at` = '2010-03-18 15:01:22') LIMIT 1
    => nil
    

    March 18th, 2010 @ 07:20 PM

  2. José Valim
    José Valim
    • State changed from new to wontfix

    It's always saved in the database as UTC. You can configure the format on READ by changing config/environment.rb.

    March 27th, 2010 @ 01:54 PM