Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Timezone Adjustment?

Reply
Thread Tools

Timezone Adjustment?

 
 
Lon Baker
Guest
Posts: n/a
 
      12-01-2004
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



 
Reply With Quote
 
 
 
 
zunda
Guest
Posts: n/a
 
      12-01-2004
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/



 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      12-01-2004

"zunda" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) .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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TimeZone change - how to use TimeZone class axrock Java 8 03-25-2009 11:54 PM
TimeZone calculation on Windows Vista with DateTime::TimeZone Ami Perl Misc 5 09-24-2007 07:27 AM
Convert windows TimeZone to Java TimeZone asaf Java 3 09-11-2006 05:40 PM
Linux and Windows timezone problem Keith Firefox 1 10-01-2005 02:02 PM
Forum timezone stlava The Lounge 5 06-29-2005 09:49 AM



Advertisments