diff --git a/xscen/catutils.py b/xscen/catutils.py index 9ec9c36b..d96cd7ce 100644 --- a/xscen/catutils.py +++ b/xscen/catutils.py @@ -90,7 +90,10 @@ def _parse_level(text: str) -> str: return text -@register_parse_type("datebounds", regex=r"(([\d]+(\-[\d]+)?)|fx)", group_count=3) +# Minimum 4 digits for a date (a single year). Maximum is, in theory, YYYYMMDDHHMMSS so 14. +@register_parse_type( + "datebounds", regex=r"(([\d]{4,15}(\-[\d]{4,15})?)|fx)", group_count=3 +) def _parse_datebounds(text: str) -> tuple[str, str]: """Parse helper to translate date bounds, used in the special DATES field.""" if "-" in text: diff --git a/xscen/utils.py b/xscen/utils.py index 71d05fc0..cf1e2571 100644 --- a/xscen/utils.py +++ b/xscen/utils.py @@ -206,7 +206,7 @@ def _parse_date(date, fmts): except (KeyError, ValueError): try: date = pd.Timestamp(date) - except pd._libs.tslibs.parsing.DateParseError: + except (pd._libs.tslibs.parsing.DateParseError, ValueError): date = pd.NaT elif isinstance(date, cftime.datetime): for n in range(3):