Robin Rosicky
Robin Rosicky

Reputation: 325

Timezone conversions incorrect in Rails when using Time.zone

Time.zone = 'Asia/Kolkata'
Time.zone 
=> (GMT+05:30) Asia/Kolkata

Time.zone has been set properly.

Time.zone.parse('0000-01-01 03:00:00 UTC').strftime('%l:%M %p')
=> " 8:53 AM"

Incorrect offset being applied (+05:33 vs +05:30)

Why does this happen? Is there a better way?

Upvotes: 0

Views: 71

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180887

The time zone in Calcutta before 1941 seems to have been 5 hours, 53 minutes ahead of UTC.

If you use a year later than that (for example year 2000) instead of year 0, you should get the result you expect.

Due to daylight savings time, you can't really convert a UTC time to a local time, 8:00UTC can convert to different local times in summer and winter. For automatic conversion to give the correct result, you need a full date, not just a time.

Upvotes: 1

Related Questions