[TZInfo-users] TzInfo timezone base question
phil.ross at gmail.com
Wed Feb 6 15:54:46 EST 2008
On 06/02/2008, Mark Van De Vyver <mvyver at gmail.com> wrote:
> On Feb 7, 2008 7:11 AM, Philip Ross <phil.ross at gmail.com> wrote:
> > There is no equivalent of the parse function in TZInfo. You could use
> > parse and do the following though:
> > tz = TZInfo::Timezone.get(source_tz)
> > src_time_as_utc = tz.local_to_utc(Time.parse("09:30" + " UTC", tz.now))
> Sorry I wasn't clearer, but in my case the time string 09:30 refers to
> the source_tz, which is _not_ my local tz nor UTC, and this source tz
> may change in different calls to the method I'm trying to write. I'd
> like to get a time object that is in the source_tz, but have abandond
> this idea, and will settle for an iso8601 string that contains the
> time in the source tz.
My example does do what you want. "09:30" + " UTC" creates a Time that
is in UTC, but TZInfo treats it as though it were in source_tz.
I'm creating the Time in UTC to avoid any problems that might occur as
a result of daylight savings rules in the system timezone.
> > Adding " UTC" to the time forces it to be parsed as a UTC timestamp
> > and causes any daylight savings rules of the system timezone to be
> > ignored. TZInfo will still treat the time value as if it were in local
> > time (it ignores the timezone aspect of the Time).
> Thanks I suppose I could + "<something-else>". But I may be getting
> confused again, I'd like TZInfo to treat the time as if it were in the
> source_tz rather than my local tz.
When using local_to_utc or any other method that takes a local time as
a parameter, TZInfo will always treat the time as though it were in
source_tz. It ignores any Timezone information in the Time and just
reads the year, month, day, hour, minute and second values.
> > This would work too. TZInfo will just read the year, month, day, hour,
> > minute and second of the Time passed to local_to_utc and ignore the
> > timezone. It doesn't matter if Time.local returns a different timezone
> > to source_tz.
> Sorry, I'm confused, I thought that by calling tz =
> TZInfo::Timezone.get(source_tz), it means that in a call to
> 'tz.local_to_utc' that the 'local in 'local_to_utc' refers to the
> source_tz and not the system's tz. Is this correct?
Yes, that is correct.
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
More information about the TZInfo-users