Forum: Ruby on Rails DateTime in Linux

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
80b82d737cb818a877b18a46ef8dc4a1?d=identicon&s=25 Charles (Guest)
on 2008-11-01 00:12
(Received via mailing list)
I'm new to Ruby and have been pulling my hair out trying to figure out
an issue with displaying DateTime fields. I have programmed a very
simple app in Windows with a MySQL 5 database. The DateTime fields
appear to be saved in a UTC format. When displaying DateTime
information with the following -

<%=h evt.start_time.to_time %>

I see the following output (on Windows)

2008-10-31 03:00:00 -0700

In the database the value of the start_time field is - 2008-10-31
10:00:00. It appears "evt.start_time.to_time" is displaying DateTime
in localtime (MST).

However, the same code on my LINUX (CentOS 5) box yields the following
output -

2008-10-31 10:00:00 UTC

What am I missing? I've verified time, timezone and NTP settings on
the LINUX box.

I have the following setup in my environment.rb -

config.time_zone = 'Arizona'

I'm at a complete loss. Any help would be greatly appreciated.

C
F47bebf5f4b10b709a59310027c8f977?d=identicon&s=25 Robert Zotter (Guest)
on 2008-11-01 00:21
(Received via mailing list)
Charles,

I am not sure what you want to accomplish. If you want to display the
time you have listed in your database you can always use the
following.

<%= h evt.start_time.to_s(:db) %>

Is this what you are looking for?
--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

http://www.zapient.com
http://www.fromjavatoruby.com
80b82d737cb818a877b18a46ef8dc4a1?d=identicon&s=25 Pete Barnes (Guest)
on 2008-11-01 00:41
(Received via mailing list)
Robert,

I think what I need to do is convert a DateTime value. stored in the
MYSQL
db, of 2008-10-31 21:00:00 (UTC) to 2008-10-31 14:00:00 -0700 (AZ time).

Cheers.

**
F47bebf5f4b10b709a59310027c8f977?d=identicon&s=25 Robert Zotter (Guest)
on 2008-11-03 20:47
(Received via mailing list)
Try this.

>> evt.start_time.in_time_zone('Arizona')

Check out
http://api.rubyonrails.org/classes/ActiveSupport/C....
And http://api.rubyonrails.org/classes/ActiveSupport/T...
lists all the available timezones.

--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

http://www.zapient.com
http://www.fromjavatoruby.com
80b82d737cb818a877b18a46ef8dc4a1?d=identicon&s=25 Pete Barnes (Guest)
on 2008-11-05 07:05
(Received via mailing list)
I already tried that mate! No joy.

Now this ruby script is the Java equivalent of an application - not
rendered
through a browser. Does that make a difference? This is list of my gems
-

*** LOCAL GEMS ***

actionmailer (2.1.1, 2.1.0)
actionpack (2.1.1, 2.1.0)
activerecord (2.1.1, 2.1.0)
activeresource (2.1.1, 2.1.0)
activesupport (2.1.1, 2.1.0)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
fastthread (1.0.1)
gem_plugin (0.2.3)
jicksta-adhearsion (0.7.999)
log4r (1.0.5)
mbleigh-subdomain-fu (0.0.2)
mongrel (1.1.5)
mysql (2.7)
rails (2.1.1, 2.1.0)
rake (0.8.2, 0.8.1)
rspec (1.1.4)
rubigen (1.3.2)

I'm using a MYSQL 5.0.45 for a the database. The field is defined as a
DateTime.

This is the line of code that I can not get into localtime -

start_time = evt.start_time.in_time_zone('Arizona')

DB value : 2008-11-17 15:00:00

However, the same line of code on a web portal displays the correct
localtime.

On my portal page : Monday Nov 17 8am

In my ruby app. the value of start_time is : 2008-11-17 15:00:00 -0700

Not very helpful!

Many thanks for your kind assistance.

C.
This topic is locked and can not be replied to.