Skip to content

Commit

Permalink
Merge pull request #60 from DavidDoukhan/main
Browse files Browse the repository at this point in the history
time precision 10
  • Loading branch information
dahlia authored Jul 7, 2024
2 parents de0eaaf + 25eea55 commit 9e6d07d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ on all of them.

The easiest to install ``tox`` is to use ``pip`` [#]_::

pip install tox tox-pip-version
pip install tox

Once you've installed ``tox``, it's very simple to run the test suite on
all Python versions this project aims to support::
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 (7, 9, 11, 14):
if p in (7, 9, 10, 11, 14):
continue
with raises(DatavalueError):
d(fx_client, datatype, other_value(precision=p))
# precision (other than 7, 9, 11 or 14) is unsupported
# precision (other than 7, 9, 10, 11 or 14) is unsupported


def test_decoder_monolingualtext(fx_client: Client):
Expand Down
8 changes: 6 additions & 2 deletions wikidata/datavalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
import collections.abc
import datetime
from typing import TYPE_CHECKING, Any, Mapping, Union
from typing import TYPE_CHECKING, Any, Mapping, Tuple, Union

from .client import Client
from .commonsmedia import File
Expand Down Expand Up @@ -147,6 +147,7 @@ def time(self,
client: Client,
datavalue: Mapping[str, object]) -> Union[datetime.date,
datetime.datetime,
Tuple[int, int],
int]:
value = datavalue['value']
if not isinstance(value, collections.abc.Mapping):
Expand Down Expand Up @@ -198,6 +199,9 @@ def time(self,
if precision == 9:
# The time only specifies the year.
return int(time[1:5])
if precision == 10:
# this time only specifies year and month (no day)
return (int(time[1:5]), int(time[6:8]))
if precision == 11:
return datetime.date(int(time[1:5]), int(time[6:8]),
int(time[9:11]))
Expand All @@ -208,7 +212,7 @@ def time(self,
).replace(tzinfo=datetime.timezone.utc)
else:
raise DatavalueError(
'{!r}: time precision other than 7, 9, 11 or 14 is '
'{!r}: time precision other than 7, 9, 10, 11 or 14 is '
'unsupported'.format(precision),
datavalue
)
Expand Down

0 comments on commit 9e6d07d

Please sign in to comment.