Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

time_select form helper interprets new time object as UTC not as configured time zone

I am running into what to me seems like a simple issue, but I can't figure out what I am doing wrong. In my app users can add their course through a simple form_for. They can enter a start_time and end_time for the course's lectures, like so:

<div class="field">
  Start Time<br />
  <%= time_select :course, :start_time, { :minute_step => 5, :ampm => true } %>
</div>

<div class="field">
  End Time<br />
  <%= time_select :course, :end_time, { :minute_step => 5, :ampm => true } %>
</div>

I configured my time zone in application.rb to be set to Eastern Time and this seems to work correctly as created_at is returned in the right time zone.

However, the problem I am encountering is that start_time and end_time are entered as UTC into the database. So when a user selects a class to start at 10 AM it is entered as 10 UTC not 10 AM EST / 15:00 UTC. What am I missing here? It seems like what I want to happen should be possible.

like image 654
Philip V Avatar asked Nov 05 '22 08:11

Philip V


1 Answers

Summarizing the answer from the comments in order to remove this question from the "Unanswered" filter:

Suggested by Tim Brandes:

Maybe this helps you: Timezone with rails 3 ... I have never used a time_select but always a datetime_select when dealing with timezones, maybe this could be an issue, but it seems rather unlikely.

Solution that worked for Philip V:

My start_time and end_time are not being saved within the time zone but saved as a UTC time. ... I changed the column type for start_time and end_time to datetime and this fixed the issues I had. I guess time columns only allow UTC.

like image 98
DreadPirateShawn Avatar answered Nov 10 '22 05:11

DreadPirateShawn