# Time default format: How to override

**URL:** <https://www.ruby-forum.com/t/time-default-format-how-to-override/65906>\
**Category:** Ruby\
**Created:** [August 22, 2006, 9:47am UTC](https://www.ruby-forum.com/t/time-default-format-how-to-override/65906 "2006-08-22T09:47:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [August 22, 2006, 9:47am UTC](https://www.ruby-forum.com/t/time-default-format-how-to-override/65906/1 "2006-08-22T09:47:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [August 22, 2006, 10:47am UTC](https://www.ruby-forum.com/t/time-default-format-how-to-override/65906/2 "2006-08-22T10:47:29Z")

</div>

Hi,

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 😉

–  
Martins

---

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [August 22, 2006, 1:23pm UTC](https://www.ruby-forum.com/t/time-default-format-how-to-override/65906/3 "2006-08-22T13:23:50Z")

</div>

Martins wrote:

> 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???

---

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [August 22, 2006, 1:53pm UTC](https://www.ruby-forum.com/t/time-default-format-how-to-override/65906/4 "2006-08-22T13:53:53Z")

</div>

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 …

–  
Martins
