Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time precision 10 #60

Merged
merged 5 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading