diff --git a/augur/dates/__init__.py b/augur/dates/__init__.py index 046638826..10116523a 100644 --- a/augur/dates/__init__.py +++ b/augur/dates/__init__.py @@ -121,6 +121,12 @@ def get_numerical_date_from_value(value, fmt=None, min_max_year=None): except InvalidDate as error: raise AugurError(str(error)) from error return [treetime.utils.numeric_date(d) for d in ambig_date] + if value.startswith('[') and value.endswith(']') and len(value[1:-1].split(':'))==2: + # Treetime ambiguous date format, e.g. [2019.5:2020.5] + try: + return [float(x) for x in value[1:-1].split(':')] + except ValueError as error: + raise AugurError(str(error)) from error try: return treetime.utils.numeric_date(datetime.datetime.strptime(value, fmt)) except: diff --git a/tests/dates/test_dates.py b/tests/dates/test_dates.py index 1427ea3fa..ed7b3fb90 100644 --- a/tests/dates/test_dates.py +++ b/tests/dates/test_dates.py @@ -99,3 +99,7 @@ def test_get_numerical_dates_dict_error(self): } with pytest.raises(AugurError): dates.get_numerical_dates(metadata) + + def test_get_numerical_date_from_value_treetime_ambiguous_date_format(self): + assert dates.get_numerical_date_from_value("[2019.5:2020.5]") == [2019.5, 2020.5] + assert dates.get_numerical_date_from_value("[2013.543:2013.544]") == [2013.543, 2013.544]