Why a nil date makes I18n.l fail?


#1

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


#2

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 P. removed_email_address@domain.invalid


#3

2009/10/12 Fernando P. removed_email_address@domain.invalid:

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