Ruby on Rails Time Without Time Zone
In Ruby and Rails, there is no class dedicated to time-of-day, so 2000–01–01 is used for the time. ActiveModel implements a Time class to reflect the database type of time. And it will convert the time according to your app’s timezone Rails.application.config.time_zone
Suddenly, our time has increased by 10/11 hours after upgrading our Rails 4 application to Rails 5, since it took 08:31:00
and converted it to Sydney time Sat, 01 Jan 2000 19:31:00 AEDT +11:00
. In daylight saving, its 11+, otherwise its 10+ hours.
In our use case we only saving just purely time, it doesn't have to relate any daylight savings or time zone, we only needed model.time_value.strftime(“ %R”)
to tell it just time without converting it with added timezone.
We save time
in postgres with time_field
and field DDL is time_value time
, also we use user profile base timezones to parse data and time
Let’s take an example values shown directly from database:
time_value
------------
08:31:00
(1 row)
And when you see rails c output
model.time_value
=> Sat, 01 Jan 2000 19:31:00 AEDT +11:00model.time_value.strftime('%R')
=> "19:31"
Take another, database value
time_value
…