dev | 2016-07-22 00:00:00 +0000

Offsetting Ruby Time

Hellonext, Inc.

Hellonext Team

Managing local time is such a huge challenge when making webapps. There's always going to be users from all over the world clocking in on different timezones. Basecamp's local_time solves this problem in a elegant way – it doesn't care how you store timezone, it interprets the users local time and prints it out on the view accordingly.

But, all hell breaks loose when you try to recreate this on the server side. Here there's no information on what user is from what timezone.

And even if you persist the users timezone information, surprisingly Rails doesn't come with an out of the box solution to offseting time(s).

Here's a super simple way to convert a UTC time to a zone of your choice, by just inputting the offset.
  => Fri, 22 Jul 2016 07:56:38 UTC +00:00
  => Fri, 22 Jul 2016 13:26:38 UTC +00:00

{% gist 4d20c8989172351268173c4f16421208 %}

Last updated: September 7th, 2023 at 7:42:06 AM GMT+0

Hellonext Blogpost Author Profile

Hellonext Team

Hellonext is a user feedback tool and this article was written by many people at Hellonext. Hellonext helps prioritize product roadmap based on user-input.