[TZInfo-users] TzInfo timezone base question

Mark Van De Vyver mvyver at gmail.com
Wed Feb 6 14:46:26 EST 2008


Hi Philip,

Thanks for the prompt response....

On Feb 7, 2008 12:43 AM, Philip Ross <phil.ross at gmail.com> wrote:
> On 06/02/2008, Mark Van De Vyver <mvyver at gmail.com> wrote:
> > Hi,
> > Thanks for the work that has gone into making tzinfo available, and
> > for making it freely available!
> >
> > I'm trying to figure out a way to obtain a Time instance that has a
> > 'specific' timezone.  The twist is I just start with a time string.
> >
> > Is there a way to do this using tzinfo?
>
> Hi Mark,
>
> The Ruby Time class only supports representing times in either UTC or
> the local timezone of the system.
>
> On Unix based architectures, the local timezone can be changed at
> runtime by setting the TZ environment variable. This will affect all
> Times constructed after changing the environment variable. For
> example:
>
> > ENV['TZ']='Australia/Melbourne'
> => "Australia/Melbourne"
> > Time.parse("09:30").iso8601
> => "2008-02-07T09:30:00+11:00"
> > ENV['TZ']='Asia/Karachi'
> => "Asia/Karachi"
> > Time.parse("09:30").iso8601
> => "2008-02-06T09:30:00+05:00"

Thanks for the clarification, so there is no way to achieve a similar
effect using tzinfo.

> On Windows, changing the TZ environment variable has no effect (see
> http://www.ruby-forum.com/topic/68570#88607).
>
> Because of the limitations of the Time class, TZInfo always returns
> UTC Time instances and ignores the timezone of Times that are passed
> in.

OK this is where I got a little confused - apologies if this is
obvious, so it seems to do what I want I can't use 'parse', but
instead will have to extract the hrs and minutes, then use:

tz = TZInfo::Timezone.get(source_tz)
src_time_as_utc = tz.local_to_utc(Time.local(2005,8,29,src_hrs,src_mins,0))

Thanks for the clarification.

Regards
Mark

> Regards,
>
> Phil
>
> --
> Phil Ross
> http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
>


More information about the TZInfo-users mailing list