Forum: Ruby on Rails Wierdness with time.getutc.localtime

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jd G. (Guest)
on 2009-04-06 22:02
I'm new to Ruby/Rails and trying to understand Time/Date/DateTime. I
came across this weirdness while playing around and was wondering if
someone can tell me what is going on here:

>> w = Work.find(9)
=> #<Work id: 9, [...] created_at: "2009-04-06 16:29:43" [...]>
>> w.created_at.class
=> ActiveSupport::TimeWithZone
>> w.created_at
=> Mon, 06 Apr 2009 16:29:43 UTC +00:00
>> w.created_at.getutc
=> Mon Apr 06 16:29:43 UTC 2009
>> w.created_at
=> Mon, 06 Apr 2009 16:29:43 UTC +00:00
>> w.created_at.localtime
=> Mon Apr 06 10:29:43 -0600 2009
>> w.created_at
=> Mon, 06 Apr 2009 16:29:43 UTC +00:00

OK, all good so far.

>> w.created_at.getutc.localtime
=> Mon Apr 06 10:29:43 -0600 2009
>> w.created_at
=> Mon, 06 Apr 2009 10:29:43 UTC +00:00

WTF, why did this change the value of w.created_at? As far as I can tell
from the documentation there shouldn't be any side effects from these
calls.

Thanks for any clarification, C
This topic is locked and can not be replied to.