Time class and time zones


#1

Question in brief:
Is it possible to create a Time object with a time zone other than the
local time zone or GMT?

I’m relatively new to Ruby (coming from the Java world), and after
reading the docs and playing with Time a fair bit, I’ve decided that you
can’t create a Time object with an arbitrary time zone. Is this correct?

For example, let’s say my local time zone is PDT (GMT-8). Can I create a
Time object representing 16:00 EDT (GMT-5) in New York? Sure, I know I
can represent that time as 13:00 PDT or 21:00 GMT, but that’s not what I
want to do.

I’m writing an app that deals with user time zones across the globe. If
I normalize my users’ times to local or GMT, I lose information. I.e., I
would like my app to remember times exactly as it was input–if a time
was input as Eastern Time (US), it should be displayed as Eastern Time
upon retrieval. Can I store the time zone datum in the Time object, or
must I persist an addition time zone field along with the Time object?
The downside to keeping track of the time zone externally is that I
can’t take advantage of Time’s format method and it just seems kludgy in
general.

I’d appreciate any feedback. Perhaps I’m going about this the wrong way.
Thanks much!

–Ed Lau


#2

Ed Lau wrote:

Question in brief:
Is it possible to create a Time object with a time zone other than the
local time zone or GMT?

Slightly tangential to your question, but they might lead to
some ideas:

http://redhanded.hobix.com/inspect/showingPerfectTime.html
http://redhanded.hobix.com/bits/showingPerfectTimePerfectPlusEdition.html

Regards,


#3

Check out http://tzinfo.rubyforge.org/

TZInfo is a Ruby library that uses the standard tz (Olson) database to
provide daylight savings aware transformations between times in
different
time zones. The tz database is compiled into Ruby classes which are
packaged in the release. No external zoneinfo files are required at
runtime.

All the best
JE


#4

Quoting removed_email_address@domain.invalid, on Mon, May 15, 2006 at 11:40:18PM +0900:

Check out http://tzinfo.rubyforge.org/

TZInfo is a Ruby library that uses the standard tz (Olson) database to
provide daylight savings aware transformations between times in different
time zones. The tz database is compiled into Ruby classes which are
packaged in the release. No external zoneinfo files are required at
runtime.

Hey, thats great! I’ve wanted to make vPim timezone-aware for a while,
but haven’t had the energy. It looks like it won’t be too hard with
this.

Thanks,
Sam