jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/871015 )
Change subject: [Bugfix] Correctly adjust for timezones during comparisons ......................................................................
[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(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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):