Nikhil
Nikhil

Reputation: 55

saving time as per the user selected time_zone specified in rails

I have a scenario where I have events, and events has_many sessions. The events table has time_zone field and the session start_time and end_time is related to this time zone. I want to store the start_time and end_time in UTC format in the db and display the time as per the events time_zone. Also what would be the unit test scenarios for the above case.

Upvotes: 0

Views: 30

Answers (1)

Hardik Gondaliya
Hardik Gondaliya

Reputation: 326

In ROR database always stores time in UTC format, to display time according to zone you can use

start_time.in_time_zone(time_zone).strftime("%b %e, %a %l:%M %p %Z")

eg.

start_time.in_time_zone('Mumbai').strftime("%b %e, %a %l:%M %p %Z")

Upvotes: 1

Related Questions