code: def is_valid_interval(edtf_candidate):
      from_date = None
      to_date = None
      end, start = 'pos', 'pos'
      if edtf_candidate.count('/') == 1:
          edtf_candidate = replace_all(edtf_candidate, interval_replacements)
          edtf_candidate = re.sub(U_PATTERN, replace_u, edtf_candidate)
          parts = edtf_candidate.split('/')
          if parts[0].startswith("-"):
              start = 'neg'
              parts[0] = parts[0][1:]
          if parts[1].startswith("-"):
              end = 'neg'
              parts[1] = parts[1][1:]
          if start == 'pos' and end == 'neg':
              return False
          if parts[0].startswith("0000") or parts[1].startswith("0000"):
              return zero_year_special_case(parts[0], parts[1], start, end)
          if parts[0].count("-") == 2:
              from_date = datetime.datetime.strptime(parts[0], "%Y-%m-%d")
          if parts[1].count("-") == 2:
              to_date = datetime.datetime.strptime(parts[1], "%Y-%m-%d")
          if parts[0].count("-") == 1:
              from_date = datetime.datetime.strptime(parts[0], "%Y-%m")
          if parts[1].count("-") == 1:
              to_date = datetime.datetime.strptime(parts[1], "%Y-%m")
          if parts[0].count("-") == 0:
              if parts[0] == 'unknown':
                  from_date = datetime.datetime.strptime("0001", "%Y")
              else:
                  from_date = datetime.datetime.strptime(parts[0], "%Y")
          if parts[1].count("-") == 0:
              if parts[1] == 'open' or parts[1] == 'unknown':
                  to_date = 'open'
              else:
                  to_date = datetime.datetime.strptime(parts[1], "%Y")
          if start == 'neg' and end == 'pos':
              return True
          elif start == 'neg' and end == 'neg':
              if from_date >= to_date and from_date and to_date:
                  return True
          elif (
              parts[1] == 'unknown' or
              parts[1] == 'open' or
              parts[0] == 'unknown'
          ):
              return True
          elif start == 'pos' and end == 'pos':
              if from_date <= to_date and from_date and to_date:
                  return True
          else:
              return False
      else:
          return False