ruby - Rails app thinks it's April 12 when it's actually April 11. How do I sync timezones? -


i have game model. in db/seeds creating several game objects:

game.create(id: 9, date: "2014-4-11 12am", time: "705pm", opponent: "jacksonville", away: false, event: "friday night fireworks") game.create(id: 10, date: "2014-4-12 12am", time: "630pm", opponent: "jacksonville", away: false, event: "grill giveaway") 

inside of view looping through @games see if game.date equal today's date.

<% games.each |game| %>   <% if activesupport::timezone["central time (us & canada)"].parse(game.date.to_s).utc.to_date.strftime("%_m/%d")[1..-1] == time.zone.now.strftime("%_m/%d")[1..-1] && game.away == false %> 

however, when output

<%= activesupport::timezone["central time (us & canada)"].parse(game.date.to_s).utc.to_date.strftime("%_m/%d")[1..-1] %> 

it returns "4/12". skips first game in seeds file, 1 date of today, 4/11, , outputs next game date of 4/12.

at 7:00pm on 4/11:

time.zone.now.strftime("%_m/%d")[1..-1] 

outputs "4/12".

and

<%= activesupport::timezone["central time (us & canada)"].parse(game.date.to_s).utc.to_date.strftime("%_m/%d")[1..-1] %> 

outputs "4/12"

the thing can think of system thinks it's 4/12 somehow, why it's skipping on first game date of 4/11?

i'm not sure how match these up. , fyi, put config.time_zone = 'central time (us & canada)' inside application.rb

edit

another development: in rails console in terminal when run time.zone.now returns fri, 11 apr 2014 20:25:15 cdt -05:00

but when run <%= time.zone.now %> inside view in application outputs 2014-04-12 01:25:49 utc

i recommend using date , datetime data types , leave out time - , @mu short said don't append times onto date values

here blog post wrote on rails , timezones: http://jessehouse.com/blog/2013/11/15/working-with-timezones-and-ruby-on-rails/

inside of view looping through @games see if game.date equal today's date.

try instead:

<% time.use_zone("central time (us & canada)") %>   <% games.each |game| %>     <% if game.date == date.current %>       game on! today     <% end %>   <% end %> <% end %> 

again, please read blog post (sample code well). set app utc default , change other zones 'on demand' needed (usually based on user settings).


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -