From 69aa945a269d16859c69357f7304afbcbcf032f0 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 4 May 2024 07:06:55 +0000 Subject: [PATCH] Handle another time precision --- matcher/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/matcher/utils.py b/matcher/utils.py index 144b7cb..dbe850f 100644 --- a/matcher/utils.py +++ b/matcher/utils.py @@ -188,9 +188,10 @@ class WikibaseTime(typing.TypedDict): def format_wikibase_time(v: WikibaseTime) -> str | None: - """Format wikibase time value into human readable string.""" + """Format Wikibase time value into human readable string.""" t = v["time"] + ordinal_num: str match v["precision"]: case 11: # year, month and day return date.fromisoformat(t[1:11]).strftime("%-d %B %Y") @@ -202,7 +203,11 @@ def format_wikibase_time(v: WikibaseTime) -> str | None: return f"{t[1:4]}0s" case 7: # century century = ((int(t[:5]) - 1) // 100) + 1 - ordinal_num: str = num2words(abs(century), to="ordinal_num") + ordinal_num = num2words(abs(century), to="ordinal_num") return f"{ordinal_num} {century}{' BC' if century < 0 else ''}" + case 6: # millennium + millennium = ((int(t[:5]) - 1) // 1000) + 1 + ordinal_num = num2words(abs(millennium), to="ordinal_num") + return f"{ordinal_num} millennium{' BC' if millennium < 0 else ''}" case _: # not handled return None