Parsing with different formats instead only with default #12

caironoleto opened this Issue May 9, 2012 · 5 comments

3 participants


Hi mate!

In our project, we have the following config locale:

    default: "%d/%m/%Y"
    competence: "%m/%Y"

Sometimes we need handle a date field in competence format, but we don't want to change our default format, we want to use competence format.

How we can do that?


Right now it's not possible to do it. An idea for next releases is to have not only the default key, but a list of keys to be translated. This list would be prioritized, and it'd try to parse using each one in the list until it finds one that matches, or none.

I think that'd solve the problem, because you'd be able to remove the default key from the parsing list and use any other formats you want. What do you think?


Good! With this can solve my problem.


@carlosantoniodasilva since you merged the custom parsers features, you could use the same custom parsers to do the inverse way.

Maybe, something like that:

module MyCustomDateParser
  include I18n::Alchemy::DateParser

  extend self

  def localize(value)
    I18n.localize value, :format => :custom

  def parse(value)
    return value unless valid_for_parsing?(value)

    if parsed_date = Date._strptime(value, i18n_format)


  def i18n_format
    I18n.t(:custom, :scope => [:date, :formats])

I'm thinking this will work :)

Could you confirm that, @caironoleto ?


@sobrinho yes, it should be possible to use these custom parsers to handle different formats, I just want to make it easier for this to happen, but I didn't have the time to think about it and implement something yet :). And with that in mind, I think that the idea of allowing a list of keys to be translated will die. Hopefully I'll be able to get into all this this week. Cheers!


@sobrinho, Sure. I will close this issue, it's not more necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment