docs: def todate(val):
      '''Convert val to a datetime.date instance by trying several
      conversion algorithm.
      If it fails it raise a ValueError exception.
      '''
      if not val:
          raise ValueError("Value not provided")
      if isinstance(val, datetime):
          return val.date()
      elif isinstance(val, date):
          return val
      else:
          try:
              ival = int(val)
              sval = str(ival)
              if len(sval) == 8:
                  return yyyymmdd2date(val)
              elif len(sval) == 5:
                  return juldate2date(val)
              else:
                  raise ValueError
          except Exception:
              # Try to convert using the parsing algorithm
              try:
                  return date_from_string(val).date()
              except Exception:
                  raise ValueError("Could not convert %s to date" % val)