Skip to content

Commit 68f0b36

Browse files
committed
Handle UA markers to the left of the year segment
- include `year_ua_b` in the set of attributes to check when determining whether a date is uncertain, approximate, or both - if there is no month, omit it from the stringification; this corrects a bug where `~1945` would turn into `~1945-None` after parsing and stringification
1 parent f00f7a9 commit 68f0b36

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

edtf/parser/parser_classes.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ def __init__(
858858

859859
uas = [
860860
year_ua,
861+
year_ua_b,
861862
month_ua,
862863
day_ua,
863864
year_month_ua,
@@ -886,7 +887,10 @@ def __str__(self):
886887
else:
887888
y = f"{self.year_ua_b}{self.year}" if self.year_ua_b else str(self.year)
888889

889-
m = f"{self.month_ua}{self.month}" if self.month_ua else str(self.month)
890+
if self.month:
891+
m = f"{self.month_ua}{self.month}" if self.month_ua else str(self.month)
892+
else:
893+
m = None
890894

891895
if self.day:
892896
d = f"{self.day_ua}{self.day}" if self.day_ua else str(self.day)
@@ -902,7 +906,12 @@ def __str__(self):
902906
else:
903907
result = f"{y}-({m}-{d}){self.month_day_ua}"
904908
else:
905-
result = f"{y}-{m}-{d}" if d else f"{y}-{m}"
909+
if d:
910+
result = f"{y}-{m}-{d}"
911+
elif m:
912+
result = f"{y}-{m}"
913+
else:
914+
result = y
906915

907916
if self.all_ua:
908917
result = f"({result}){self.all_ua}"

0 commit comments

Comments
 (0)