2
votes

Okay this has got to be the oddest rails related issue ever. It was brought to my attention about a month ago when some of our Employees started to notice that everytime the enter a value in a date field and save, then later come back to it, it is always 2 days behind what they saved. This is a very consistent issue. I would have been fine if it was just that web app. But it has started happening in ALL our rails applications. I have checked the server times. They all are correct. Correct date, year, time, timezone, etc. And what is even more peculiar is we have imported some data and the date field says '2013-04-15' however when pulling up that exact entry in rails it says '2013-04-13' exactly 2 days off. (Even without formatting the time with strftime) This is starting to drive me crazy. The only work around I have is to take the values and add 2.days but that is not going to cut it across several web applications. Does anyone have any ideas that might shed some light on this.

***As a side note this does not occur in development mode.

********* Finally Found the answer after months of struggling. It was how I was connecting to the database. When we switched to MSSQL 2012 I started using a non standard gem to connect to SQL 2012 because the standard wasn't working with our sql config so I used the gem. -> gem "jdbc-mssql-azure", "~> 0.0.1". Apparently there is a bug somewhere in that gem that causes dates to render 2 days backwards regardless of the SQL value. Thank you guys for all the comments and help. Also it may help people in the US to use the "amarican-date" gem

1
Does you production server has the right Time? Is it showing the right date + time for today & now?MrYoshiji
Yes the sever has the correct time(Iv checked like a billion times). And I would see this happening on maybe one server, but this is happening on all 4 of our rails servers. It is odd that across all three the date is off by 2 days.user1579627
Have you checked your db server time? If these dates are coming in from requests, can you confirm in the logs that the date passed in params is correct? Can you run console in production mode, create a dummy entry, and recreate the same behavior?PinnyM
@user1579627 have you checked your database time?Paulo Fidalgo
This may provide some debug inspiration: infiniteundo.com/post/25326999628/…Narfanator

1 Answers

0
votes

It's a bit hard to post THE answer when we do not have more information.

If server and database time is correct and it don't occur in development mode, I'd say the problem lays in the environment/production.rb file.

These two settings in particular might cause timing issues.

config.time_zone                      #sets the default time zone 
                                      #for the application and enables
                                      #time zone awareness for Active Record.

config.active_record.default_timezone #default is :utc