From 3c8d5b3f9e35a678983d6d3ce883f1602af618e0 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Fri, 30 Aug 2024 17:45:57 -0700 Subject: [PATCH] Search on years before -9999 and after 9999 (#11420) * Search on years before -9999 and after 9999 * Update changelog --- arches/app/utils/date_utils.py | 21 ++++++++++++++++++++- releases/7.5.4.md | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arches/app/utils/date_utils.py b/arches/app/utils/date_utils.py index ec76a33ba53..2cd30403e1a 100644 --- a/arches/app/utils/date_utils.py +++ b/arches/app/utils/date_utils.py @@ -69,6 +69,20 @@ def __init__( except Exception as err: self.error = err raise err + + def get_long_year(self, date): + """ + Dates with long years will fail to parse unless properly formatted. + Example: '-200000-01-01' and '20000-01-01' will fail to parse. + The day and month must be stripped and the year prefixed with a y. + """ + + date_elements = date.split("-") + if len(date_elements) == 4: + long_year = f"y-{date_elements[1]}" + if len(date_elements) == 3: + long_year = f"y{date_elements[0]}" + return long_year def parse(self, date=None): if date is None: @@ -91,7 +105,12 @@ def parse(self, date=None): except Exception: pass - self.edtf = parse_edtf(date) + try: + self.edtf = parse_edtf(date) + except Exception as e: #Exception is likely because year has more than 4 digits + long_year = self.get_long_year(date) + self.edtf = parse_edtf(long_year) + result = self.handle_object(self.edtf) if isinstance(result, list): self.result_set = result diff --git a/releases/7.5.4.md b/releases/7.5.4.md index 89a454891b1..9ef17ccaf6d 100644 --- a/releases/7.5.4.md +++ b/releases/7.5.4.md @@ -9,6 +9,7 @@ Arches 7.5.4 Release Notes is specified #11120 - Allow main (left) nav to scroll to content height when expanded #11243 - Ensure resource type search filter dropdown is not displayed beneath search filter buttons #11188 +- Fix search failure when filtering on dates with years having more than 4 digits, #11419 ### Dependency changes: ```