Skip to content

Commit

Permalink
Merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahankinson committed Aug 13, 2024
1 parent ddd8f7b commit 8c4f968
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
18 changes: 10 additions & 8 deletions edtf/natlang/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from typing import Optional

from dateutil.parser import parse
from dateutil.parser import ParserError, parse

from edtf import appsettings

Expand Down Expand Up @@ -126,9 +126,9 @@ def text_to_edtf(text: str) -> Optional[str]:
is_after = re.findall(AFTER_CHECK, t)

if is_before:
result = f"unknown/{result}"
result = f"/{result}"
elif is_after:
result = f"{result}/unknown"
result = f"{result}/"

return result

Expand Down Expand Up @@ -172,7 +172,7 @@ def text_to_edtf_date(text: str) -> Optional[str]:
# detect CE/BCE year form
is_ce = re.findall(CE_RE, t)
if is_century:
result = "%02dxx" % (int(is_century[0][0]) - 1,)
result = "%02dXX" % (int(is_century[0][0]) - 1,)
is_approximate = is_approximate or re.findall(APPROX_CENTURY_RE, t)
is_uncertain = is_uncertain or re.findall(UNCERTAIN_CENTURY_RE, t)

Expand Down Expand Up @@ -214,8 +214,10 @@ def text_to_edtf_date(text: str) -> Optional[str]:
default=DEFAULT_DATE_2,
)

except ValueError:
return None
except ParserError:
return
except Exception:
return

if dt1.date() == DEFAULT_DATE_1.date() and dt2.date() == DEFAULT_DATE_2.date():
# couldn't parse anything - defaults are untouched.
Expand All @@ -234,12 +236,12 @@ def text_to_edtf_date(text: str) -> Optional[str]:
# approximate/uncertain markers to decide whether we treat it as
# a century or a decade.
if i == 2 and could_be_century and not (is_approximate or is_uncertain):
result += "x"
result += "X"
elif i == 3 and is_decade:
if mentions_year:
result += "X" # year precision
else:
result += "x" # decade precision
result += "X" # decade precision
elif date1[i] == date2[i]:
# since both attempts at parsing produced the same result
# it must be parsed value, not a default
Expand Down
1 change: 1 addition & 0 deletions edtf/parser/parser_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import date, datetime
from operator import add, sub
from time import struct_time
from typing import Optional

from dateutil.relativedelta import relativedelta

Expand Down

0 comments on commit 8c4f968

Please sign in to comment.