Forum: Ruby on Rails Why a nil date makes I18n.l fail?

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.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-10-12 22:20
I's all in the title!

I find it very painful, to always have to supply a date so that I18n.l
doesn't miserably fail. Why doesn't simply return ""???
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick Lloyd (ricklloyd)
on 2009-10-13 00:41
(Received via mailing list)
Because that's how it's coded.

from: I18n::Backend.localize...

def localize(locale, object, format = :default)
        raise ArgumentError, "Object must be a Date, DateTime or Time
object. #{object.inspect} given." unless object.respond_to?(:strftime)


On Oct 12, 4:20 pm, Fernando Perez <rails-mailing-l...@andreas-s.net>
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-10-13 10:00
(Received via mailing list)
2009/10/12 Fernando Perez <rails-mailing-list@andreas-s.net>:
>
> I's all in the title!
>
> I find it very painful, to always have to supply a date so that I18n.l
> doesn't miserably fail. Why doesn't simply return ""???

If you find yourself repeatedly doing something then your code is not
DRY.  The solution might be to provide your own wrapper and call that.

Colin
This topic is locked and can not be replied to.