Using Rails 3 and PostgreSQL 8, I have a fuel_date column with data type "timestamp without time zone". A user selects a date and time from dropdown menu in their local time and when it's submitted to server, it should be saved as UTC time:
def create_fuel_service
attributes = {}
fuel_service_hash = params[:fuel_service]
datetime = DateTime.new(fuel_service_hash["fuel_date(1i)"].to_i, fuel_service_hash["fuel_date(2i)"].to_i,
fuel_service_hash["fuel_date(3i)"].to_i, fuel_service_hash["fuel_date(4i)"].to_i,
fuel_service_hash["fuel_date(5i)"].to_i).in_time_zone(current_user.time_zone).utc
attributes[:fuel_date] = datetime
fuel_service = FuelService.new(attributes)
if fuel_service.save
...
However, the record is saved as localtime, not UTC time, even though the created_at and updated_at fields are saved as UTC time:
http://s22.postimg.org/caho7v6c1/utctime_issue.png
How can I convert the fuel_date field to UTC time before saving? Using the UTC time method of DateTime does nothing.