Timezone Adjustment?

I am new to Ruby and am hitting a wall when it comes to "displaying" the date/time from a database and justing it for the a users local timezone in a web application.

Is there a simple way of doing this?

My experience in coming from the world of Java it was relatively easy. But I have not been able to find a easy manner of doing this in Ruby.

Any help would be greatly appreciated.

···

--
Lon

Hi,

"displaying"
the date/time from a database and justing it for the a users local
timezone in a web application.

Is there a simple way of doing this?

What I have been doing is to play with the environment variable TZ:

  t = Time.now
  ENV['TZ'] = 'HST'
  puts t.localtime #=> Tue Nov 30 19:25:55 HST 2004
  ENV['TZ'] = 'Japan'
  u = Time.at( t )
  puts t.localtime #=> Tue Nov 30 19:25:55 HST 2004
  puts u.localtime #=> Wed Dec 01 14:25:55 JST 2004

It seems that we have to create a new Time object to change timezone.
I also like to know more sofisticated ways to do this.

Thanks,
zunda

···

__________________________________
STOP HIV/AIDS.
Yahoo! JAPAN Redribbon Campaign
http://pr.mail.yahoo.co.jp/redribbon/

"zunda" <zunda616e@yahoo.co.jp> schrieb im Newsbeitrag
news:20041201053055.64878.qmail@web2305.mail.yahoo.co.jp...

Hi,

> "displaying"
> the date/time from a database and justing it for the a users local
> timezone in a web application.
>
> Is there a simple way of doing this?

What I have been doing is to play with the environment variable TZ:

  t = Time.now
  ENV['TZ'] = 'HST'
  puts t.localtime #=> Tue Nov 30 19:25:55 HST 2004
  ENV['TZ'] = 'Japan'
  u = Time.at( t )
  puts t.localtime #=> Tue Nov 30 19:25:55 HST 2004
  puts u.localtime #=> Wed Dec 01 14:25:55 JST 2004

It seems that we have to create a new Time object to change timezone.

Yeah, it seems so.

I also like to know more sofisticated ways to do this.

Sounds like a candidate for an RCR. Ideall we would like to have
Time#zone= (i.e. assignment).

It seems as if Time.utc and Time.local ignore the time zone argument (is
this a bug?). Here are my tests:

09:16:05 [robert.klemme]: ruby /c/temp/ruby/times.rb
[6, 16, 10, 1, 12, 2004, 3, 336, false, "GMT+2:00"]
[6, 16, 10, 1, 12, 2004, 3, 336, false, "GMT+1:00"]
Wed Dec 01 10:16:06 GMT+2:00 2004
Wed Dec 01 10:16:06 GMT+2:00 2004
Wed Dec 01 10:16:06 UTC 2004
GMT+2:00
GMT+2:00
UTC
1101888966
1101888966
1101896166
-1101888966
0
-7200
09:16:06 [robert.klemme]: cat /c/temp/ruby/times.rb

t1 = Time.now
a = t1.to_a
p a
a[-1] = "GMT+1:00"
p a
t2 = Time.local(*a)
t3 = Time.utc(*a)

all = [t1,t2,t3]
puts all
puts all.map{|t| t.zone}
i = all.map{|t| t.to_i}
puts i
i.inject(0) {|last,t| puts last-t;t}

Kind regards

    robert