Forum: Ruby on Rails Rails Time.now and system locale

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.
Ashkey (Guest)
on 2007-03-05 18:59
(Received via mailing list)
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
Richard L. (Guest)
on 2008-06-16 21:42
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.
This topic is locked and can not be replied to.