Forum: Ruby on Rails Time zone mapping from TimeZone to TZInfo::Timezone

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
13e4ba7f654dbbdd186d702c06c8b24c?d=identicon&s=25 Morten (Guest)
on 2007-04-19 19:50
(Received via mailing list)
Hi. Using this:

    <%= time_zone_select("account", "time_zone" %>

I get a list of time zones options, like eg.:

    <option value="Athens">(GMT+02:00) Athens</option>

But as I'm using TZInfo::Timezone, I need to map 'Athens' to

I can see that the mapping I'm looking for is present in the
tzinfo_timezone plugin, but I cannot see how to access it.




PS: I'm aware that I could use

<%=time_zone_select("account", "time_zone",
TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) %>

But the resulting select values look horrible, so I'd like to stick
with the Rails presentation format.
57eb16f53a88985923d2afcc418b853f?d=identicon&s=25 Selva (Guest)
on 2007-04-28 18:05
(Received via mailing list)
Hi Morten,

<%=time_zone_select("account", "time_zone",
TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) %>

Actually the code you mentioned above will give a result in the format
you are looking for.
i.e  'Europe/Athens'

$tcode = @params[:account][:time_zone]
tz = TZInfo::Timezone.get($tcode)
tz = tz.local_to_utc(Time::now()).to_s

So, 'tz' will provide you the converted time.

Hope it helps you and others.

This topic is locked and can not be replied to.