Skip to content

Commit

Permalink
Merge pull request #59 from BaptisteBayche/58-time_pecision_7
Browse files Browse the repository at this point in the history
add precision 7
  • Loading branch information
dahlia authored Jun 26, 2024
2 parents fea1c3e + bd1c795 commit de0eaaf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down
4 changes: 2 additions & 2 deletions tests/datavalue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion wikidata/datavalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
)
Expand Down

0 comments on commit de0eaaf

Please sign in to comment.