[LRUG] extending Time for use throughout rails
Andrew Stewart
boss at airbladesoftware.com
Fri Dec 28 12:06:00 PST 2007
On 28 Dec 2007, at 18:41, Dafydd Rees wrote:
> Hello,
>
> I want to add the concept of "geek format" (e.g. 2007-12-31) to the
> standard time class. This is how I do it:
>
> class Time
> def geektime
> strftime('%Y-%m-%d')
> end
> end
>
> In what file (and where) should I put this code in my rails app so
> it's accessible in all of my rails code?
>
> The responsibilities should settle down soon and I can palm this work
> off to an object in one part of the system but until that happens I'd
> like to stash in in the Time class.
You're not the first -- this is ISO 8601 :)
This might help:
http://www.yup.com/articles/2006/04/13/iso-8601-dates-in-ruby-on-rails
Or you could build on this:
$ irb
>> require 'time'
=> true
>> Time.now.iso8601
=> "2007-12-28T20:04:24+00:00"
Regards,
Andy Stewart
-------
http://airbladesoftware.com
More information about the Chat
mailing list