From 3dfece9f5b695bf2500ced7ad6958cbaf824ee3c Mon Sep 17 00:00:00 2001 From: baptiste bayche Date: Tue, 25 Jun 2024 09:30:26 -0400 Subject: [PATCH 1/3] add precision 7 --- wikidata/datavalue.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wikidata/datavalue.py b/wikidata/datavalue.py index 9ccb014..5356a6e 100644 --- a/wikidata/datavalue.py +++ b/wikidata/datavalue.py @@ -193,6 +193,8 @@ def time(self, precision = value['precision'] except KeyError: raise DatavalueError('precision field is missing', datavalue) + if precision == 7: + return int(time[1:3]) if precision == 9: # The time only specifies the year. return int(time[1:5]) @@ -206,7 +208,7 @@ def time(self, ).replace(tzinfo=datetime.timezone.utc) else: raise DatavalueError( - '{!r}: time precision other than 9, 11 or 14 is ' + '{!r}: time precision other than 7, 9, 11 or 14 is ' 'unsupported'.format(precision), datavalue ) From b3f3260131aefba09075e0bfd6be8b2fc830089e Mon Sep 17 00:00:00 2001 From: baptiste bayche Date: Tue, 25 Jun 2024 11:22:35 -0400 Subject: [PATCH 2/3] add changelog entry --- docs/changes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index db66049..e50c85b 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -15,7 +15,7 @@ To be released. were incorrectly typed. - :class:`wikidata.multilingual.MultilingualText`'s constructor became to take only :class:`Locale` for parameter ``locale``. - +- Added date precision 7 in :class:`wikidata.datavalue.decoder` [:pr:`59`] Version 0.7.0 ------------- From bd1c795c5275a235d8644d9889066ccc39c36c66 Mon Sep 17 00:00:00 2001 From: baptiste bayche Date: Tue, 25 Jun 2024 12:15:47 -0400 Subject: [PATCH 3/3] fix test test_decoder__time --- tests/datavalue_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/datavalue_test.py b/tests/datavalue_test.py index be76ecf..b97b06c 100644 --- a/tests/datavalue_test.py +++ b/tests/datavalue_test.py @@ -130,11 +130,11 @@ def other_value(**kwargs) -> Dict[str, object]: d(fx_client, datatype, other_value(precision=None)) # precision field is missing for p in range(1, 15): - if p in (9, 11, 14): + if p in (7, 9, 11, 14): continue with raises(DatavalueError): d(fx_client, datatype, other_value(precision=p)) - # precision (other than 11 or 14) is unsupported + # precision (other than 7, 9, 11 or 14) is unsupported def test_decoder_monolingualtext(fx_client: Client):