Rails Time.now and system locale


#1

hi everyone, I have a problem with dates output.

Actually if in Rails’ ./script/console I send a “Time.now” I get a
localized
date, something like: “lun mar 05 19:33:00 CET 2007”
Actually my server has environment variables set for Italy, here’s the
output of the locale command:
LANG=it_IT@euro
LC_CTYPE=“it_IT@euro”
LC_NUMERIC=“it_IT@euro”
LC_TIME=“it_IT@euro”
LC_COLLATE=“it_IT@euro”
LC_MONETARY=“it_IT@euro”
LC_MESSAGES=“it_IT@euro”
LC_PAPER=“it_IT@euro”
LC_NAME=“it_IT@euro”
LC_ADDRESS=“it_IT@euro”
LC_TELEPHONE=“it_IT@euro”
LC_MEASUREMENT=“it_IT@euro”
LC_IDENTIFICATION=“it_IT@euro”
LC_ALL=

The strange thing is that the standard Ruby IRB doesn’t consider the
environment locale, and sending “Time.now” i get the following output:
irb(main):001:0> Time.now
=> Mon Mar 05 19:37:04 CET 2007

So I can desume that Rails, instead, make use of the system locale
automagically…

I defeinitely disagree with this behaviour, is there a way I can handle
it
to give me international output by default?


Ashkey < Jules Piccotti


#2

Ashkey wrote:

Actually if in Rails’ ./script/console I send a “Time.now” I get a
localized
date, something like: “lun mar 05 19:33:00 CET 2007”

The strange thing is that the standard Ruby IRB doesn’t consider the
environment locale, and sending “Time.now” i get the following output:
irb(main):001:0> Time.now
=> Mon Mar 05 19:37:04 CET 2007

It looks like you’ve answered your own question. In Rails you’ve
overridden default behavior with localization settings. Thus, when you
run console, you’re inheriting the localization. IRB does not load your
Rails configuration. My guess is that your server settings are set for
a different locale - which is what IRB is inheriting.