Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gedcom7/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
ucletter = '[A-Z]'
tagchar = f'({ucletter}|[0-9]|{underscore})'
exttag = f'{underscore}({tagchar})+'
calendar = f'(GREGORIAN|JULIAN|FRENCH_R|HEBREW|{exttag})'
daterestrict = 'FROM|TO|BET|AND|BEF|AFT|ABT|CAL|EST'
calendar = f'(?!{daterestrict})(GREGORIAN|JULIAN|FRENCH_R|HEBREW|{exttag})'
day = f'{integer}'
stdtag = f'{ucletter}({tagchar})*'
month = f'({stdtag}|{exttag})'
month = f'(?!{daterestrict})({stdtag}|{exttag})'
year = f'{integer}'
epoch = f'(BCE|{exttag})'
epoch = f'(?!{daterestrict})(BCE|{exttag})'
date = f'({calendar}{d})?(({day}{d})?{month}{d})?{year}({d}{epoch})?'
date_capture = f'((?P<calendar>{calendar}){d})?(((?P<day>{day}){d})?(?P<month>{month}){d})?(?P<year>{year})({d}(?P<epoch>{epoch}))?'
dateapprox = f'(?P<qualifier>ABT|CAL|EST){d}(?P<dateapprox>{date})'
dateexact = f'(?P<day>{day}){d}(?P<month>{month}){d}(?P<year>{year})'
dateperiod = f'((TO{d}(?P<todate1>{date}))?|FROM{d}(?P<fromdate>{date})({d}TO{d}(?P<todate2>{date}))?)'
daterange = f'(BET{d}(?P<between>{date}){d}AND{d}(?P<and>{date})|AFT{d}(?P<after>{date})|BEF{d}(?P<before>{date}))'
daterestrict = '(FROM|TO|BET|AND|BEF|AFT|ABT|CAL|EST|BCE)'
datevalue = f'({date}|{dateperiod}|{daterange}|{dateapprox})?'
tag = f'({stdtag}|{exttag})'
enum = f'{tag}'
Expand Down
2 changes: 1 addition & 1 deletion gedcom7/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def parse(self) -> Dict[str, Union[str, int]]:
match = self.match.groupdict()
return {
"calendar": match["calendar"],
"day": int(match["day"]),
"day": int(match["day"]) if match["day"] else None,
"month": match["month"],
"year": int(match["year"]),
"epoch": match["epoch"],
Expand Down
37 changes: 37 additions & 0 deletions test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ def test_date():
"year": 2022,
"epoch": "BCE",
}
assert T.DateValue("11 JAN 2022").parse() == {
"calendar": None,
"day": 11,
"month": "JAN",
"year": 2022,
"epoch": None,
}
assert T.DateValue("JAN 2022").parse() == {
"calendar": None,
"day": None,
"month": "JAN",
"year": 2022,
"epoch": None,
}
assert T.DateValue("2022").parse() == {
"calendar": None,
"day": None,
"month": None,
"year": 2022,
"epoch": None,
}


def test_dateperiod():
Expand All @@ -149,6 +170,22 @@ def test_dateperiod():
"epoch": None,
},
}
assert T.DatePeriod("FROM 2021 TO 2022").parse() == {
"from": {
"calendar": None,
"year": 2021,
"month": None,
"day": None,
"epoch": None,
},
"to": {
"calendar": None,
"year": 2022,
"month": None,
"day": None,
"epoch": None,
},
}
assert T.DatePeriod("FROM 1 JAN 2021 TO 11 JAN 2022").parse() == {
"from": {
"calendar": None,
Expand Down