for TimeWithZone object, how to change the zone part only?
- by leomayleomay
I have a table Coupon with a field expired_at, which is of datetime type, and before I save the record, I want to change the zone part of the field according to the user's choice. Say,
c = Coupon.new
c.expired_at = DateTime.now
c.expired_at_timezone = "Arizona"
c.save!
and in the coupon.rb
class Coupon << ActiveRecord::Base
def before_save
# change the zone part here, leave the date and time part alone
end
end
What I'm saying is if the admin want the coupon expired at 2014-07-01 10:00 am, Arizona time, the expired_at stored in the db should be like this:
Tue, 01 Jul 2014 10:00:00 MST -07:00
is there any way I can modify the zone part only and leave the date and time part alone?
Thanks