def to_date(date, year = nil)
      if match = date.to_s.match(DATE)
        year ||= "20#{match['year'] || Date.today.strftime('%y')}"
        month = match['month']
        day = match['day']
        Date.new(year.to_i, month.to_i, day.to_i)
      else
        date
      end
    rescue ArgumentError # let's simply ignore invalid dates
      date
    end
def to_date(date, year = nil)
      if match = date.to_s.match(DATE)
        year ||= "20#{match['year'] || Date.today.strftime('%y')}"
        month = match['month']
        day = match['day']
        Date.new(year.to_i, month.to_i, day.to_i)
      else
        date
      end
    rescue ArgumentError # let's simply ignore invalid dates
      date
    end
Internal: Converts a provided string into a date object
     In MT940 documents the date is provided as a 6 char string (YYMMDD) or as a 4 char string (MMDD)
     If a 4 char string is provided a second parameter with the year should be provided. If no year is present the current year is assumed.

 Example:

 to_date('140909')
 to_date('0909', 2014)

 Retuns a date object or the provided date value if it is not parseable.