Repository: unt-libraries/edtf-validate

Issue:
Handle `ValueError` in `is_valid_interval`
If you call `is_valid_interval` with a string that contains a date with a time component,  you get a `ValueError` such as in:
```
>>> is_valid_interval('1985-04-12T23:20:30/1990-02-10T23:12:30')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "edtf-validate/edtf_validate/valid_edtf.py", line 468, in is_valid_interval
    from_date = datetime.datetime.strptime(parts[0], "%Y-%m-%d")
  File "python3.7/_strptime.py", line 577, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/opt/lib/python3.7/_strptime.py", line 362, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: T23:20:30
```

We should catch this type of error both in converting the "to" and "from" date and return that it is an invalid interval.

Discussion:

Patch:
diff --git a/edtf_validate/valid_edtf.py b/edtf_validate/valid_edtf.py
index 53dd491..e7f73d5 100644
--- a/edtf_validate/valid_edtf.py
+++ b/edtf_validate/valid_edtf.py
@@ -465,9 +465,15 @@ def is_valid_interval(edtf_candidate):
             return zero_year_special_case(parts[0], parts[1], start, end)
         # 2 '-' characters means we are matching year-month-day
         if parts[0].count("-") == 2:
-            from_date = datetime.datetime.strptime(parts[0], "%Y-%m-%d")
+            try:
+                from_date = datetime.datetime.strptime(parts[0], "%Y-%m-%d")
+            except ValueError:
+                return False
         if parts[1].count("-") == 2:
-            to_date = datetime.datetime.strptime(parts[1], "%Y-%m-%d")
+            try:
+                to_date = datetime.datetime.strptime(parts[1], "%Y-%m-%d")
+            except ValueError:
+                return False
         # handle special case of same year season/season range due to
         # the overlap of the months we are designating for the seasons
         if parts[0].count("-") == 1 and parts[1].count("-") == 1:


Test patch:
diff --git a/tests/test_valid_edtf.py b/tests/test_valid_edtf.py
index b74d118..90876a2 100644
--- a/tests/test_valid_edtf.py
+++ b/tests/test_valid_edtf.py
@@ -272,6 +272,9 @@ invalid_edtf_intervals = [
     'Y-61000/-2000',
     '2004-06-11%/2004-%06',
     '2004-06-11%/2004-06~',
+    '2005-07-25T10:10:10Z/2006-01-01T10:10:10Z',
+    '2005-07-25T10:10:10Z/2006-01',
+    '2005-07-25/2006-01-01T10:10:10Z',
 ]
 
 invalid_edtf_datetimes = [