After deploying my rails app to a VPS I had some problems with 'time'. After some puzzling I found out that Rails is acting in a strange way when using the date/time conversion.
My server is set to timezone "Amsterdam" and in the Rails config I also have set timezome to "Amsterdam"
example:
I receive this string via my body content in a json/api
date = "13-03-2015 09:29"
when I convert this string like this:
date.to_datetime
, the result is "Fri, 13 Mar 2015 09:29:00 +0000"
when I convert the string like this:
date.to_time
, the result is "2015-03-13 09:29:00 +0100"
As you can see there is a difference in the way it is adding the time correction "+0000" vs "+0100"
So when I convert like this:
date.to_time.to_datetime
, the result is "Fri, 13 Mar 2015 09:29:00 +0100"
And this is the result I needed, because my postgres database otherwise gave me back a wrong date (+1 hour)
My questions are:
What is the explanation for the difference in behaviour of
.to_date and
and.to_datetime
How does Postgres handle dates. When saving a datetime parameter like this "Fri, 13 Mar 2015 09:29:00 +0000" and I render this date in a json response it is 1 hour later.
Hope someone can explain this to me.
Martijn