Time default format: How to override

  • Thread starter Jesper Rønn-Jensen
  • Start date
J

Jesper Rønn-Jensen

I'm working on a Rails plugin that localizes default Time/Date formats.
I want to override the standard month and daynames with local variants,
but for some reason I can't override the default Time month and
daynames.

irb(main):010:0> Time.new
=> Mon Aug 21 20:47:52 Romance Daylight Time 2006
irb(main):011:0> Time::RFC2822_DAY_NAME
=> ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
irb(main):012:0> Time::RFC2822_DAY_NAME = %{søn man tir ons tor fre
lør}
(irb):12: warning: already initialized constant RFC2822_DAY_NAME
irb(main):014:0> Time.new
=> Mon Aug 21 20:49:36 Romance Daylight Time 2006

As you see from the above: The dayname is not overridden. How do I
override it?

However, I can easily override the locale format (at leas when I do it
from Rails). But that doesn't help much when month and daynames are
still in English.

Please let me know your thoughts on how I change English month and
daynames to local.
 
J

jesperrr

Martins said:
I am using Date library like this:

require 'date'
Date::DAYNAMES.replace %w(Svetdiena Pirmdiena Otrdiena Tresdiena
Ceturtdiena Piektdiena Sestdiena)
puts Date.today.strftime('%A') #=> Otrdiena
Otrdiena is Tuesday only in Latvian ;)

Thanks Martins.
I know how to modify the Date with this and use the same technique
already in my Rails plugin Localization Simplified.

Only, on the Time class these constants don't exist but somehow on
Time.new they're used anyhow.

Problem is, that it doesn't help modifying constants on Date, because
when I do that, Time class has already access to the original DAYNAMES.

Try for yourself Time.new in your code.

Any suggestions on how to modify day/month names on Time class???
 
1

13

I see. Then you should look at your OS locale settings, because
Time#to_s (and maybe Time#strftime & etc too) are using strftime()
function to create formetted time string ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top