ruby - Rails model attribute (a DateTime) has different value depending on how its called -


i using rails 4.2 , ruby 2.2.0. have model called ride has datetime attribute called start_time. when call ride.find(1803), start_time shown january 9th. when call ride.find(1803).start_time, returns start_time on january 9th. how possible , how fix it? here's full code ran in console:

irb(main):028:0> ride.find(1803) => #<ride id: 1803, start_time: "2016-01-09 00:00:00", end_time: nil, created_at: "2016-01-05 16:55:44", updated_at: "2016-01-05 20:35:38", user_id: 29, ride_type: nil, horse_id: nil, notes: "", available_to_ride_additional_horses: nil, admin_approved: false, weekday: nil, unavailable_to_ride: false, time_range_dropdown: "morning", rider_name: "matti fisher", rider_last_name: "fisher", rider_first_name: "matti", edited_at: nil, requested_time: "2016-01-09 19:30:00"> irb(main):029:0> ride.find(1803).start_time => fri, 08 jan 2016 19:00:00 est -05:00 

this because date/time value stored in database utc , default implementation of inspect activerecord model doesn't apply timezone conversion.

however, when access date/time value, rails apply current timezone settings.

you can math. since timezone utc-5, both datetime represent same object

2016-01-09 00:00:00 utc fri, 08 jan 2016 19:00:00 est -05:00 

as proof, can call

ride.find(1803).start_time.utc 

and date/time utc, same value see when print out full record representation.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -