jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/811365 )
Change subject: [doc] Update documentation ......................................................................
[doc] Update documentation
Change-Id: I0d8605af83b8b6666a97118b8ed5166b4de9a4af --- M ROADMAP.rst M docs/api_ref/pywikibot.rst M docs/tests_ref/index.rst R docs/tests_ref/time_tests.rst M pywikibot/time.py M scripts/CHANGELOG.md 6 files changed, 45 insertions(+), 7 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst index 5369b93..e4c072b 100644 --- a/ROADMAP.rst +++ b/ROADMAP.rst @@ -1,6 +1,13 @@ Current release 7.5.0 ^^^^^^^^^^^^^^^^^^^^^
+* New :mod:`pywikibot.time` module with new functions and timezone class in addition to `Timestamp` +* :meth:`Page.revisions()<pywikibot.page.BasePage.revisions>` supports more formats/types for + starttime and endtime parameters, in addition to those allowed by + :meth:`Timestamp.fromISOformat()<pywikibot.Timestamp.fromISOformat>`. +* New :meth:`Timestamp.set_timestamp()<pywikibot.Timestamp.set_timestamp>` method +* Fully ISO8601 and POSIX format support with :class:`pywikibot.Timestamp`; + formats are compliant with MediaWiki supported formats * Handle asynchronous page_put_queue after KeyboardInterrupt in Python 3.9+ (:phab:`T311076`) * No longer expect a specific namespace alias in cosmetic_changes :meth:`translateAndCapitalizeNamespaces diff --git a/docs/api_ref/pywikibot.rst b/docs/api_ref/pywikibot.rst index cd8f47c..76d1495 100644 --- a/docs/api_ref/pywikibot.rst +++ b/docs/api_ref/pywikibot.rst @@ -144,6 +144,11 @@
.. automodule:: pywikibot.throttle
+pywikibot.time module +--------------------- + +.. automodule:: pywikibot.time + pywikibot.titletranslate module -------------------------------
diff --git a/docs/tests_ref/index.rst b/docs/tests_ref/index.rst index a91bc2d..695a506 100644 --- a/docs/tests_ref/index.rst +++ b/docs/tests_ref/index.rst @@ -69,7 +69,7 @@ textlib<./textlib_tests> thanks<./thanks_tests> thread<./thread_tests> - timestamp<./timestamp_tests> + time<./time_tests> timestripper<./timestripper_tests> tk<./tk_tests> tools_chars<./tools_chars_tests> diff --git a/docs/tests_ref/timestamp_tests.rst b/docs/tests_ref/time_tests.rst similarity index 75% rename from docs/tests_ref/timestamp_tests.rst rename to docs/tests_ref/time_tests.rst index 1620a09..c7f436a 100644 --- a/docs/tests_ref/timestamp_tests.rst +++ b/docs/tests_ref/time_tests.rst @@ -1,7 +1,7 @@ tests.timestamp_tests module =============================
-.. automodule:: tests.timestamp_tests +.. automodule:: tests.time_tests :members: :undoc-members: :show-inheritance: diff --git a/pywikibot/time.py b/pywikibot/time.py index cee0acf..29b5fea 100644 --- a/pywikibot/time.py +++ b/pywikibot/time.py @@ -1,4 +1,7 @@ -"""Time handling module.""" +"""Time handling module. + +.. versionadded:: 7.4 +""" # # (C) Pywikibot team, 2007-2022 # @@ -22,7 +25,7 @@ 'TZoneUTC', )
- +#: ..versionadded:: 7.4 MW_KEYS = types.MappingProxyType({ 's': 'seconds', 'h': 'hours', @@ -57,6 +60,9 @@
Use Site.server_time() for the current time; this is more reliable than using Timestamp.utcnow(). + + .. versionchanged:: 7.4 + moved to :mod:`time` module """
mediawikiTSFormat = '%Y%m%d%H%M%S' # noqa: N815 @@ -74,6 +80,8 @@ - ISO8601 format: YYYY-MM-DD[T ]HH:MM:SS[Z|±HH[MM[SS[.ffffff]]]] - POSIX format: seconds from Unix epoch S{1,13}[.ffffff]]
+ .. versionadded: 7.4 + :param ts: Timestamp, datetime.datetime or str :return: Timestamp object :raises ValueError: conversion failed @@ -89,7 +97,10 @@
@staticmethod def _from_datetime(dt: datetime.datetime) -> 'Timestamp': - """Convert a datetime.datetime timestamp to a Timestamp object.""" + """Convert a datetime.datetime timestamp to a Timestamp object. + + .. versionadded: 7.4 + """ return Timestamp(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo) @@ -99,6 +110,8 @@ """Convert a string in MW format to a Timestamp object.
Mediwiki timestamp format: YYYYMMDDHHMMSS + + .. versionadded: 7.4 """ RE_MW = r'\d{14}$' # noqa: N806 m = re.match(RE_MW, timestr) @@ -115,6 +128,8 @@
ISO8601 format: - YYYY-MM-DD[T ]HH:MM:SS[[.,]ffffff][Z|±HH[MM[SS[.ffffff]]]] + + .. versionadded: 7.4 """ RE_ISO8601 = (r'(?:\d{4}-\d{2}-\d{2})(?P<sep>[T ])' # noqa: N806 r'(?:\d{2}:\d{2}:\d{2})(?P<u>[.,]\d{1,6})?' @@ -155,6 +170,8 @@ """Convert a string in POSIX format to a Timestamp object.
POSIX format: SECONDS[.ffffff]] + + .. versionadded: 7.4 """ RE_POSIX = r'(?P<S>-?\d{1,13})(?:.(?P<u>\d{1,6}))?$' # noqa: N806 m = re.match(RE_POSIX, timestr) @@ -176,7 +193,10 @@
@classmethod def _from_string(cls: Type['Timestamp'], timestr: str) -> 'Timestamp': - """Convert a string to a Timestamp object.""" + """Convert a string to a Timestamp object. + + .. versionadded: 7.4 + """ handlers = [ cls._from_mw, cls._from_iso8601, @@ -260,11 +280,16 @@ Convert object to a POSIX timestamp.
See Note in datetime.timestamp(). + + .. versionadded: 7.4 """ return self.replace(tzinfo=datetime.timezone.utc).timestamp()
def posix_timestamp_format(self) -> str: - """Convert object to a POSIX timestamp format.""" + """Convert object to a POSIX timestamp format. + + .. versionadded: 7.4 + """ return '{ts:.6f}'.format(ts=self.posix_timestamp())
def __str__(self) -> str: diff --git a/scripts/CHANGELOG.md b/scripts/CHANGELOG.md index 98faf66..54a01a1 100644 --- a/scripts/CHANGELOG.md +++ b/scripts/CHANGELOG.md @@ -4,6 +4,7 @@ *current release*
### harvest_templates +* Add `-inverse` option for inverse claims (:phab:`T173238`) * Only follow redirects in harvest_template.py if no wikibase item exists (:phab:`T311883`)
## 7.4.0