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.

ActiveResource time changed

#942

It's like described in WhyNotWiki: You have an ActiveRecord model with a date attibute. When calling the show action in the controller in format xml, the dates shows up correctly.

But when you have a service that uses ActiveResource to get you model, the time is 2 hours before the one you entered.

For a workaround I tried to generate a Time.gm(..., (old_time.hour+2), ...) but that doesn't handle hours past 22 (raises an ArgumentError (out of range).

Reported by Graphity · August 30th, 2008 @ 08:30 AM

State: stale
Milestone: 3.x
Assigned to: Mikel Lindsaar Mikel Lindsaar
Importance: none

Activity

  1. Graphity
    Graphity

    Oh, ok, I just saw that adding hours is done by old_time+2.hours Ok, but the bug remains...

    August 30th, 2008 @ 08:42 AM

  2. Geoff Buesing
    Geoff Buesing

    Ideally, you'd be able to pull together a failing test case to prove this. Second best would be some script/console output that shows the issue.

    Also let us know which version of Rails you're using, and, if you're setting config.time_zone, what that's set to. Thanks.

    August 30th, 2008 @ 01:03 PM

  3. Graphity
    Graphity

    Ok, I built two RoR Applications (Producer and Consumer). And now I'm uploading both of them in one ZIP (Testcase-942.zip). Try the XML Output, you'll see two different times in the created-at attribute. Sorry if that's the wrong way but it's my first bug report.

    August 30th, 2008 @ 09:34 PM

  4. Graphity
    Graphity

    To add to my workaround: First I added the 2hours in a method in controllers/application.rb which, of course, is wrong. Those 2h should be added in the model resulting in a line like def start attributes["start"] = attributes["start"] + 2.hours end

    where start is the attribute of type Time.

    Oh yes, I' using Rail 2.0.2

    September 6th, 2008 @ 11:01 AM

  5. Graphity
    Graphity

    Hm, ok, I just deployed my app to the server and realized there is NO time-shifting. A friend suggested to look at the timezones and, really, there is the difference: My dev-system displays in its XML sth like 2008-09-06T17:45:08+02:00 where my production system displays 2008-09-10T11:28:29+00:00 (mind the +00:00 and +02:00 at the end).

    September 10th, 2008 @ 10:35 AM

  6. Graphity
    Graphity

    Ok, so, my current workaround is:

    
    def start
      attributes["start"] = attributes["start"] + Time.now.gmt_offset
    end
    

    in my model.

    I realized, while using the rails console, the server which gets the date from the DB displays

    
    start: 2008-09-10 11:48:00
    

    while the server which gets the date from ARes displays

    
    start: 2008-09-10 09:48:00 Z
    

    The timezone in the dev-system says its GMT+1 in Daylight Savings Time while the production-system says UTC

    September 10th, 2008 @ 11:05 AM

  7. Dan Barry
    Dan Barry

    There has been a whole bunch of time zone magic added in Rails 2.1, so you may want to consider upgrading to take advantage of this. Geoff's article about this explains all the new improvements.

    October 12th, 2008 @ 10:50 PM

  8. Pratik
    Pratik
    • State changed from new to incomplete

    January 18th, 2009 @ 06:57 AM

  9. Ryan Bigg
    Ryan Bigg
    • Assigned user set to Mikel Lindsaar

    The times returned from the controller should be UTC by default, unless you are setting Time.zone / config.time_zone to something else.

    April 10th, 2010 @ 11:27 AM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  11. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:05 PM

  12. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:05 PM