jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[Bugfix] Correctly adjust for timezones during comparisons

Bug: T325866
Change-Id: I418d105e3e5b98f0ca45b2d6293c8afe4cdc0d11
---
M pywikibot/__init__.py
M tests/wikibase_tests.py
2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index bb91042..bd665d8 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -474,7 +474,8 @@
elapsed_seconds += self.minute * 60
elapsed_seconds += self.second
if self.timezone is not None:
- elapsed_seconds += self.timezone * 60
+ # See T325866
+ elapsed_seconds -= self.timezone * 60
return elapsed_seconds

def __lt__(self, other: object) -> bool:
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 636aa02..b647ada 100755
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -6,6 +6,7 @@
# Distributed under the terms of the MIT license.
#
import copy
+import datetime
import json
import operator
import unittest
@@ -421,6 +422,21 @@
self.assertRaises(TypeError, operator.le, t1, 5)
self.assertRaises(TypeError, operator.ge, t1, 5)

+ def test_comparison_timezones(self):
+ """Test comparisons with timezones."""
+ repo = self.get_repo()
+ ts1 = pywikibot.Timestamp(
+ year=2022, month=12, day=21, hour=13,
+ tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
+ ts2 = pywikibot.Timestamp(
+ year=2022, month=12, day=21, hour=17,
+ tzinfo=datetime.timezone.utc)
+ self.assertGreater(ts1.timestamp(), ts2.timestamp())
+
+ t1 = pywikibot.WbTime.fromTimestamp(ts1, timezone=-300, site=repo)
+ t2 = pywikibot.WbTime.fromTimestamp(ts2, timezone=0, site=repo)
+ self.assertGreater(t1, t2)
+

class TestWbQuantity(WbRepresentationTestCase):


To view, visit change 871015. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I418d105e3e5b98f0ca45b2d6293c8afe4cdc0d11
Gerrit-Change-Number: 871015
Gerrit-PatchSet: 5
Gerrit-Owner: RPI2026F1 <sarkaraoyan+rpi2026f1@gmail.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged